From bad942c91944c5bd6206c741672c1bfcdefc7154 Mon Sep 17 00:00:00 2001 From: oddlama Date: Thu, 15 Dec 2022 01:36:03 +0100 Subject: [PATCH] feat: separate common user setup --- core/default.nix | 4 -- hosts/nom/default.nix | 2 + users/common/default.nix | 5 ++- users/common/htop.nix | 29 +++++++++++++++ users/common/nushell.nix | 78 +++++++++++++++++++++++++++++++++++++++ users/common/starship.nix | 29 +++++++++++++++ users/common/zsh.nix | 78 +++++++++++++++++++++++++++++++++++++++ users/root/default.nix | 22 +++++++++++ 8 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 users/common/htop.nix create mode 100644 users/common/nushell.nix create mode 100644 users/common/starship.nix create mode 100644 users/common/zsh.nix create mode 100644 users/root/default.nix diff --git a/core/default.nix b/core/default.nix index 0688639..69c499f 100644 --- a/core/default.nix +++ b/core/default.nix @@ -83,9 +83,5 @@ in { network.wait-online.anyInterface = true; }; - users.users.root = { - initialHashedPassword = "$6$EBo/CaxB.dQoq2W8$lo2b5vKgJlLPdGGhEqa08q3Irf1Zd1PcFBCwJOrG8lqjwbABkn1DEhrMh1P3ezwnww2HusUBuZGDSMa4nvSQg1"; - openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA5Uq+CDy5Pmt3If5M6d8K/Q7HArU6sZ7sgoj3T521Wm"]; - }; users.mutableUsers = false; } diff --git a/hosts/nom/default.nix b/hosts/nom/default.nix index 35dc692..39780fd 100644 --- a/hosts/nom/default.nix +++ b/hosts/nom/default.nix @@ -15,6 +15,8 @@ ../../modules/laptop.nix ../../modules/yubikey.nix ../../modules/zfs.nix + + ../../users/root ../../users/myuser ./fs.nix diff --git a/users/common/default.nix b/users/common/default.nix index 6322fa2..76290ab 100644 --- a/users/common/default.nix +++ b/users/common/default.nix @@ -7,10 +7,11 @@ #./btop.nix #./fish.nix #./git.nix - #./htop.nix + ./htop.nix #./neovim + ./nushell.nix #./ssh.nix - #./starship.nix + ./starship.nix #./tmux.nix #./xdg.nix #./zsh.nix diff --git a/users/common/htop.nix b/users/common/htop.nix new file mode 100644 index 0000000..0162702 --- /dev/null +++ b/users/common/htop.nix @@ -0,0 +1,29 @@ +{config, ...}: { + programs.htop = { + enable = true; + settings = + { + highlight_base_name = 1; + show_cpu_frequency = 1; + show_cpu_temperature = 1; + hide_kernel_threads = 1; + hide_userland_threads = 1; + } + // (with config.lib.htop; + leftMeters [ + (bar "LeftCPUs2") + (bar "Memory") + (bar "Swap") + (bar "ZFSARC") + (text "NetworkIO") + ]) + // (with config.lib.htop; + rightMeters [ + (bar "RightCPUs2") + (text "LoadAverage") + (text "Tasks") + (text "Uptime") + (text "Systemd") + ]); + }; +} diff --git a/users/common/nushell.nix b/users/common/nushell.nix new file mode 100644 index 0000000..fe8bff8 --- /dev/null +++ b/users/common/nushell.nix @@ -0,0 +1,78 @@ +{ + config, + pkgs, + ... +}: { + programs.zsh = { + enable = true; + enableAutosuggestions = true; + enableCompletion = true; + enableSyntaxHighlighting = true; + enableVteIntegration = pkgs.stdenv.isLinux; + autocd = true; + dotDir = ".config/zsh"; + history = { + expireDuplicatesFirst = true; + extended = true; + ignoreDups = true; + path = "${config.xdg.dataHome}/zsh/history"; + save = 10000; + share = true; + }; + envExtra = '' + export LESSHISTFILE="${config.xdg.dataHome}/less_history" + export CARGO_HOME="${config.xdg.cacheHome}/cargo" + ''; + initExtra = '' + nix-closure-size() { + nix-store -q --size $(nix-store -qR $(${pkgs.coreutils}/bin/readlink -e $1) ) | + ${pkgs.gawk}/bin/gawk '{ a+=$1 } END { print a }' | + ${pkgs.coreutils}/bin/numfmt --to=iec-i + } + bindkey "$${terminfo[khome]}" beginning-of-line + bindkey "$${terminfo[kend]}" end-of-line + bindkey "$${terminfo[kdch1]}" delete-char + bindkey '\eOA' history-substring-search-up + bindkey '\eOB' history-substring-search-down + bindkey "^[[A" history-substring-search-up + bindkey "^[[B" history-substring-search-down + bindkey "$$terminfo[kcuu1]" history-substring-search-up + bindkey "$$terminfo[kcud1]" history-substring-search-down + bindkey "^[[1;5C" forward-word + bindkey "^[[1;3C" forward-word + bindkey "^[[1;5D" backward-word + bindkey "^[[1;3D" backward-word + bindkey -s "^O" 'fzf | xargs -r $VISUAL^M' + bindkey -rpM viins '^[^[' + KEYTIMEOUT=1 + ${pkgs.any-nix-shell}/bin/any-nix-shell zsh | source /dev/stdin + ''; + sessionVariables = { + RPROMPT = ""; + }; + plugins = [ + { + # https://github.com/hlissner/zsh-autopair + name = "zsh-autopair"; + file = "zsh-autopair.plugin.zsh"; + src = pkgs.fetchFromGitHub { + owner = "hlissner"; + repo = "zsh-autopair"; + rev = "34a8bca0c18fcf3ab1561caef9790abffc1d3d49"; + sha256 = "1h0vm2dgrmb8i2pvsgis3lshc5b0ad846836m62y8h3rdb3zmpy1"; + }; + } + { + # https://github.com/zsh-users/zsh-history-substring-search + name = "zsh-history-substring-search"; + file = "zsh-history-substring-search.plugin.zsh"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-history-substring-search"; + rev = "0f80b8eb3368b46e5e573c1d91ae69eb095db3fb"; + sha256 = "0y8va5kc2ram38hbk2cibkk64ffrabfv1sh4xm7pjspsba9n5p1y"; + }; + } + ]; + }; +} diff --git a/users/common/starship.nix b/users/common/starship.nix new file mode 100644 index 0000000..039208c --- /dev/null +++ b/users/common/starship.nix @@ -0,0 +1,29 @@ +{lib, ...}: { + programs.starship = { + enable = true; + enableNushellIntegration = true; + settings = { + add_newline = false; + format = lib.concatStrings [ + "$username" + "$hostname" + "$directory" + "$git_branch" + "$git_commit" + "$git_state" + "$git_status" + "$character" + ]; + right_format = lib.concatStrings [ + "$cmd_duration" + "$package" + "$haskell" + "$python" + "$rust" + "$nix_shell" + "$line_break" + "$jobs" + ]; + }; + }; +} diff --git a/users/common/zsh.nix b/users/common/zsh.nix new file mode 100644 index 0000000..fe8bff8 --- /dev/null +++ b/users/common/zsh.nix @@ -0,0 +1,78 @@ +{ + config, + pkgs, + ... +}: { + programs.zsh = { + enable = true; + enableAutosuggestions = true; + enableCompletion = true; + enableSyntaxHighlighting = true; + enableVteIntegration = pkgs.stdenv.isLinux; + autocd = true; + dotDir = ".config/zsh"; + history = { + expireDuplicatesFirst = true; + extended = true; + ignoreDups = true; + path = "${config.xdg.dataHome}/zsh/history"; + save = 10000; + share = true; + }; + envExtra = '' + export LESSHISTFILE="${config.xdg.dataHome}/less_history" + export CARGO_HOME="${config.xdg.cacheHome}/cargo" + ''; + initExtra = '' + nix-closure-size() { + nix-store -q --size $(nix-store -qR $(${pkgs.coreutils}/bin/readlink -e $1) ) | + ${pkgs.gawk}/bin/gawk '{ a+=$1 } END { print a }' | + ${pkgs.coreutils}/bin/numfmt --to=iec-i + } + bindkey "$${terminfo[khome]}" beginning-of-line + bindkey "$${terminfo[kend]}" end-of-line + bindkey "$${terminfo[kdch1]}" delete-char + bindkey '\eOA' history-substring-search-up + bindkey '\eOB' history-substring-search-down + bindkey "^[[A" history-substring-search-up + bindkey "^[[B" history-substring-search-down + bindkey "$$terminfo[kcuu1]" history-substring-search-up + bindkey "$$terminfo[kcud1]" history-substring-search-down + bindkey "^[[1;5C" forward-word + bindkey "^[[1;3C" forward-word + bindkey "^[[1;5D" backward-word + bindkey "^[[1;3D" backward-word + bindkey -s "^O" 'fzf | xargs -r $VISUAL^M' + bindkey -rpM viins '^[^[' + KEYTIMEOUT=1 + ${pkgs.any-nix-shell}/bin/any-nix-shell zsh | source /dev/stdin + ''; + sessionVariables = { + RPROMPT = ""; + }; + plugins = [ + { + # https://github.com/hlissner/zsh-autopair + name = "zsh-autopair"; + file = "zsh-autopair.plugin.zsh"; + src = pkgs.fetchFromGitHub { + owner = "hlissner"; + repo = "zsh-autopair"; + rev = "34a8bca0c18fcf3ab1561caef9790abffc1d3d49"; + sha256 = "1h0vm2dgrmb8i2pvsgis3lshc5b0ad846836m62y8h3rdb3zmpy1"; + }; + } + { + # https://github.com/zsh-users/zsh-history-substring-search + name = "zsh-history-substring-search"; + file = "zsh-history-substring-search.plugin.zsh"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-history-substring-search"; + rev = "0f80b8eb3368b46e5e573c1d91ae69eb095db3fb"; + sha256 = "0y8va5kc2ram38hbk2cibkk64ffrabfv1sh4xm7pjspsba9n5p1y"; + }; + } + ]; + }; +} diff --git a/users/root/default.nix b/users/root/default.nix new file mode 100644 index 0000000..7744c38 --- /dev/null +++ b/users/root/default.nix @@ -0,0 +1,22 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; { + users.users.root = { + initialHashedPassword = "$6$EBo/CaxB.dQoq2W8$lo2b5vKgJlLPdGGhEqa08q3Irf1Zd1PcFBCwJOrG8lqjwbABkn1DEhrMh1P3ezwnww2HusUBuZGDSMa4nvSQg1"; + openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA5Uq+CDy5Pmt3If5M6d8K/Q7HArU6sZ7sgoj3T521Wm"]; + shell = pkgs.zsh; + }; + + home-manager.users.root = { + imports = [ + ../common + ]; + + home.username = config.users.users.root.name; + home.uid = config.users.users.root.uid; + }; +}