Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2024-11-19 10:31:29 +01:00
parent a3187e163d
commit 900f95169f
83 changed files with 1134 additions and 705 deletions

View file

@ -1,11 +1,13 @@
{ options
, config
, pkgs
, lib
, ...
{
options,
config,
pkgs,
lib,
...
}:
with lib;
with lib.metacfg; let
with lib.metacfg;
let
cfg = config.metacfg.user;
defaultIconFileName = "profile.jpg";
defaultIcon = pkgs.stdenvNoCC.mkDerivation {
@ -18,11 +20,17 @@ with lib.metacfg; let
cp $src $out
'';
passthru = { fileName = defaultIconFileName; };
passthru = {
fileName = defaultIconFileName;
};
};
propagatedIcon =
pkgs.runCommandNoCC "propagated-icon"
{ passthru = { fileName = cfg.icon.fileName; }; }
{
passthru = {
fileName = cfg.icon.fileName;
};
}
''
local target="$out/share/metacfg-icons/user/${cfg.name}"
mkdir -p "$target"
@ -38,9 +46,7 @@ in
initialPassword =
mkOpt str "password"
"The initial password to use when the user is first created.";
icon =
mkOpt (nullOr package) defaultIcon
"The profile picture to use for the user.";
icon = mkOpt (nullOr package) defaultIcon "The profile picture to use for the user.";
prompt-init = mkBoolOpt true "Whether or not to show an initial message when opening a new shell.";
extraGroups = mkOpt (listOf str) [ ] "Groups for the user to be assigned.";
sshKeys = mkOpt (listOf str) [
@ -49,14 +55,11 @@ in
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAYbUTKpy4QR3s944/hjJ1UK05asFEs/SmWeUbtS0cdA660sT4xHnRfals73FicOoz+uIucJCwn/SCM804j+wtM="
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMNsmP15vH8BVKo7bdvIiiEjiQboPGcRPqJK0+bH4jKD harald@lenovo.fritz.box"
] "ssh keys";
extraOptions =
mkOpt attrs { }
(mdDoc "Extra options passed to `users.users.<name>`.");
extraOptions = mkOpt attrs { } (mdDoc "Extra options passed to `users.users.<name>`.");
};
config = {
environment.systemPackages = with pkgs; [
];
environment.systemPackages = with pkgs; [ ];
metacfg.home = {
file = {
@ -68,10 +71,7 @@ in
"Videos/.keep".text = "";
"work/.keep".text = "";
".face".source = cfg.icon;
"Pictures/${
cfg.icon.fileName or (builtins.baseNameOf cfg.icon)
}".source =
cfg.icon;
"Pictures/${cfg.icon.fileName or (builtins.baseNameOf cfg.icon)}".source = cfg.icon;
};
extraOptions.programs.bash.initExtra = ''
@ -85,27 +85,25 @@ in
'';
};
users.users.${cfg.name} =
{
isNormalUser = true;
users.users.${cfg.name} = {
isNormalUser = true;
# inherit (cfg) name initialPassword;
# inherit (cfg) name initialPassword;
openssh.authorizedKeys.keys = cfg.sshKeys;
home = "/home/${cfg.name}";
group = "users";
openssh.authorizedKeys.keys = cfg.sshKeys;
home = "/home/${cfg.name}";
group = "users";
shell = pkgs.bash;
shell = pkgs.bash;
# Arbitrary user ID to use for the user. Since I only
# have a single user on my machines this won't ever collide.
# However, if you add multiple users you'll need to change this
# so each user has their own unique uid (or leave it out for the
# system to select).
uid = 1000;
# Arbitrary user ID to use for the user. Since I only
# have a single user on my machines this won't ever collide.
# However, if you add multiple users you'll need to change this
# so each user has their own unique uid (or leave it out for the
# system to select).
uid = 1000;
extraGroups = [ "wheel" ] ++ cfg.extraGroups;
}
// cfg.extraOptions;
extraGroups = [ "wheel" ] ++ cfg.extraGroups;
} // cfg.extraOptions;
};
}