This commit is contained in:
陈浩南 2023-07-27 21:14:39 +08:00
parent d0ef102996
commit 89a6a41d29
8 changed files with 162 additions and 170 deletions

View File

@ -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
]
)
];

View File

@ -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;
};
};
}

View File

@ -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;
};
};
}

View File

@ -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";
# };
# }
];
}

View File

@ -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 {});
}

161
modules/users/default.nix Normal file
View File

@ -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"
# ];
# };

View File

@ -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 {});
}