diff --git a/flake.nix b/flake.nix index 51b996e6..7bf23754 100644 --- a/flake.nix +++ b/flake.nix @@ -151,6 +151,7 @@ ./modules/virtualization ./modules/services ./modules/bugs + ./modules/users (inputs: { config = { nixos = @@ -266,10 +267,6 @@ }; }) ./modules/networking/xmunet.nix ./modules/networking/chn-PC.nix - [ ./modules/users/root.nix {} ] - [ ./modules/users/chn.nix {} ] - ./modules/home/root.nix - ./modules/home/chn.nix ] ) ]; diff --git a/modules/home/chn.nix b/modules/home/chn.nix deleted file mode 100644 index d634745b..00000000 --- a/modules/home/chn.nix +++ /dev/null @@ -1,13 +0,0 @@ -inputs: -{ - config = - { - home-manager.users.chn = { pkgs, ... }: - { - home.stateVersion = "22.11"; - programs.zsh = import ./zsh.nix { inherit pkgs; }; - programs.direnv.enable = true; - programs.direnv.nix-direnv.enable = true; - }; - }; -} diff --git a/modules/home/root.nix b/modules/home/root.nix deleted file mode 100644 index c01fd947..00000000 --- a/modules/home/root.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - config.home-manager = - { - useGlobalPkgs = true; - useUserPackages = true; - users.root = { pkgs, ... }: - { - home.stateVersion = "22.11"; - programs.zsh = import ./zsh.nix { inherit pkgs; }; - programs.direnv.enable = true; - programs.direnv.nix-direnv.enable = true; - }; - }; -} diff --git a/modules/home/zsh.nix b/modules/home/zsh.nix deleted file mode 100644 index 40ca3f47..00000000 --- a/modules/home/zsh.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ pkgs }: -{ - enable = true; - initExtraBeforeCompInit = - '' - # p10k instant prompt - P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh" - [[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT" - - HYPHEN_INSENSITIVE="true" - - export PATH=~/bin:$PATH - - function br - { - local cmd cmd_file code - cmd_file=$(mktemp) - if broot --outcmd "$cmd_file" "$@"; then - cmd=$(<"$cmd_file") - command rm -f "$cmd_file" - eval "$cmd" - else - code=$? - command rm -f "$cmd_file" - return "$code" - fi - } - - alias todo="todo.sh" - ''; - plugins = - [ - { - file = "powerlevel10k.zsh-theme"; - name = "powerlevel10k"; - src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k"; - } - { - file = "p10k.zsh"; - name = "powerlevel10k-config"; - src = ./p10k-config; - } - { - name = "zsh-lsd"; - src = pkgs.fetchFromGitHub - { - owner = "z-shell"; - repo = "zsh-lsd"; - rev = "029a9cb0a9b39c9eb6c5b5100dd9182813332250"; - sha256 = "sha256-oWjWnhiimlGBMaZlZB+OM47jd9hporKlPNwCx6524Rk="; - }; - } - # { - # name = "zsh-exa"; - # src = pkgs.fetchFromGitHub - # { - # owner = "ptavares"; - # repo = "zsh-exa"; - # rev = "0.2.3"; - # sha256 = "0vn3iv9d3c1a4rigq2xm52x8zjaxlza1pd90bw9mbbkl9iq8766r"; - # }; - # } - ]; -} diff --git a/modules/users/chn.nix b/modules/users/chn.nix deleted file mode 100644 index ea2198ea..00000000 --- a/modules/users/chn.nix +++ /dev/null @@ -1,58 +0,0 @@ -{ bootstrape ? false }: inputs: -{ - config = - { - users.users.chn = - { - isNormalUser = true; - extraGroups = inputs.lib.intersectLists - [ "adbusers" "networkmanager" "wheel" "wireshark" "libvirtd" "video" "audio" ] - (builtins.attrNames inputs.config.users.groups); - shell = inputs.pkgs.zsh; - autoSubUidGidRange = true; - } // (if bootstrape then { password = "0"; } - else { passwordFile = inputs.config.sops.secrets."password/chn".path; }); - # environment.persistence."/impermanence".users.chn = - # { - # directories = - # [ - # "Desktop" - # "Documents" - # "Downloads" - # "Music" - # "repo" - # "Pictures" - # "Videos" - - # ".cache" - # ".config" - # ".gnupg" - # ".local" - # ".ssh" - # ".android" - # ".exa" - # ".gnome" - # ".Mathematica" - # ".mozilla" - # ".pki" - # ".steam" - # ".tcc" - # ".vim" - # ".vscode" - # ".Wolfram" - # ".zotero" - - # ]; - # files = - # [ - # ".bash_history" - # ".cling_history" - # ".gitconfig" - # ".gtkrc-2.0" - # ".root_hist" - # ".viminfo" - # ".zsh_history" - # ]; - # }; - } // (if !bootstrape then { sops.secrets."password/chn".neededForUsers = true; } else {}); -} diff --git a/modules/users/default.nix b/modules/users/default.nix new file mode 100644 index 00000000..1cb4491c --- /dev/null +++ b/modules/users/default.nix @@ -0,0 +1,161 @@ +inputs: +{ + config = + let + inherit (inputs.lib) listToAttrs mkMerge; + inherit (builtins) map; + inherit (inputs.localLib) stripeTabs; + in mkMerge + [ + { + users = + { + users = + { + root.shell = inputs.pkgs.zsh; + chn = + { + isNormalUser = true; + extraGroups = inputs.lib.intersectLists + [ "adbusers" "networkmanager" "wheel" "wireshark" "libvirtd" "video" "audio" ] + (builtins.attrNames inputs.config.users.groups); + shell = inputs.pkgs.zsh; + autoSubUidGidRange = true; + }; + }; + mutableUsers = false; + }; + } + mkMerge (map (user: + { + sops.secrets."password/${user}".neededForUsers = true; + users.user.${user}.passwordFile = inputs.config.sops.secrets."password/${user}".path; + }) [ "root" "chn" ]) + { + home-manager = + { + useGlobalPkgs = true; + useUserPackages = true; + users = + let + normal = homeInputs: + { + home.stateVersion = "22.11"; + programs.zsh = + { + enable = true; + initExtraBeforeCompInit = stripeTabs + '' + # p10k instant prompt + P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh" + [[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT" + + HYPHEN_INSENSITIVE="true" + + export PATH=~/bin:$PATH + + function br + { + local cmd cmd_file code + cmd_file=$(mktemp) + if broot --outcmd "$cmd_file" "$@"; then + cmd=$(<"$cmd_file") + command rm -f "$cmd_file" + eval "$cmd" + else + code=$? + command rm -f "$cmd_file" + return "$code" + fi + } + + alias todo="todo.sh" + ''; + plugins = + [ + { + file = "powerlevel10k.zsh-theme"; + name = "powerlevel10k"; + src = "${inputs.pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k"; + } + { + file = "p10k.zsh"; + name = "powerlevel10k-config"; + src = ./p10k-config; + } + { + name = "zsh-lsd"; + src = inputs.pkgs.fetchFromGitHub + { + owner = "z-shell"; + repo = "zsh-lsd"; + rev = "029a9cb0a9b39c9eb6c5b5100dd9182813332250"; + sha256 = "sha256-oWjWnhiimlGBMaZlZB+OM47jd9hporKlPNwCx6524Rk="; + }; + } + # { + # name = "zsh-exa"; + # src = pkgs.fetchFromGitHub + # { + # owner = "ptavares"; + # repo = "zsh-exa"; + # rev = "0.2.3"; + # sha256 = "0vn3iv9d3c1a4rigq2xm52x8zjaxlza1pd90bw9mbbkl9iq8766r"; + # }; + # } + ]; + }; + programs.direnv = { enable = true; nix-direnv.enable = true; }; + }; + in + { + root = normal; + chn = normal; + }; + }; + } + ]; +} + +# environment.persistence."/impermanence".users.chn = +# { +# directories = +# [ +# "Desktop" +# "Documents" +# "Downloads" +# "Music" +# "repo" +# "Pictures" +# "Videos" + +# ".cache" +# ".config" +# ".gnupg" +# ".local" +# ".ssh" +# ".android" +# ".exa" +# ".gnome" +# ".Mathematica" +# ".mozilla" +# ".pki" +# ".steam" +# ".tcc" +# ".vim" +# ".vscode" +# ".Wolfram" +# ".zotero" + +# ]; +# files = +# [ +# ".bash_history" +# ".cling_history" +# ".gitconfig" +# ".gtkrc-2.0" +# ".root_hist" +# ".viminfo" +# ".zsh_history" +# ]; +# }; \ No newline at end of file diff --git a/modules/home/p10k-config/p10k.zsh b/modules/users/p10k-config/p10k.zsh similarity index 100% rename from modules/home/p10k-config/p10k.zsh rename to modules/users/p10k-config/p10k.zsh diff --git a/modules/users/root.nix b/modules/users/root.nix deleted file mode 100644 index 7406d049..00000000 --- a/modules/users/root.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ bootstrape ? false }: { pkgs, ... }@inputs: -{ - config = - { - users = - { - users.root = { shell = inputs.pkgs.zsh; } - // (if bootstrape then { password = "0"; } - else { passwordFile = inputs.config.sops.secrets."password/root".path; }); - mutableUsers = false; - }; - # root password in initrd: 0000 - # currently not working, might work in the future - # boot.initrd.secrets.${builtins.toString inputs.config.sops.secrets."password/root".path} - # = builtins.toFile "root-password" "$y$j9T$EHgd1EmvM54fIkuDnrAM41$WNhog3VSAdrQXljA4I7Coy8W6iRQFQ3CLOKEH6IZzJ/"; - } // (if !bootstrape then { sops.secrets."password/root".neededForUsers = true; } else {}); -}