Add helper functions for multi-user toggle support

Introduced a new file `lib.nix` containing helper functions to streamline user package management and attributes for multi-user configurations. Updated various modules to utilize these functions, enhancing code maintainability and readability.
This commit is contained in:
Danilo Reyes
2026-01-16 10:36:02 -06:00
parent 4e835aca1b
commit b89d193445
30 changed files with 196 additions and 213 deletions

View File

@@ -15,10 +15,10 @@
};
config = {
users.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
userLib = import ../lib.nix { inherit lib; };
in lib.mkMerge (map (user: {
${user}.shell = pkgs.${config.my.shell.type};
}) users);
}) (userLib.normalizeUsers config.my.toggleUsers.shell));
programs.zsh.enable = config.my.shell.type == "zsh";
};
}

View File

@@ -8,15 +8,13 @@
options.my.shell.exercism.enable = lib.mkEnableOption "Exercism coding practice platform";
config = lib.mkIf config.my.shell.exercism.enable {
users.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
userLib = import ../lib.nix { inherit lib; };
packages = builtins.attrValues {
inherit (pkgs)
exercism # learn to code
bats # testing system, required by Exercism
;
inherit (pkgs)
exercism # learn to code
bats # testing system, required by Exercism
;
};
in lib.mkMerge (map (user: {
${user}.packages = packages;
}) users);
in userLib.mkUserPackages config.my.toggleUsers.shell packages;
};
}

View File

@@ -9,17 +9,18 @@
options.my.shell.multimedia.enable = lib.mkEnableOption "multimedia CLI tools and codecs";
config = lib.mkIf config.my.shell.multimedia.enable {
sops.secrets."gallery-dl/secrets" = let
userLib = import ../lib.nix { inherit lib; };
# Use first user for secret ownership
user = if lib.isString config.my.toggleUsers.shell then config.my.toggleUsers.shell else (lib.head config.my.toggleUsers.shell);
user = userLib.getFirstUser config.my.toggleUsers.shell;
in {
sopsFile = ../../secrets/gallery.yaml;
owner = user;
mode = "0400";
};
home-manager.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
in lib.mkMerge (map (user: {
${user}.programs = {
userLib = import ../lib.nix { inherit lib; };
in userLib.mkHomeManagerUsers config.my.toggleUsers.shell (user: {
programs = {
yt-dlp = {
enable = true;
settings = {
@@ -43,18 +44,16 @@
'';
};
};
}) users);
});
users.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
userLib = import ../lib.nix { inherit lib; };
packages = builtins.attrValues {
inherit (pkgs)
ffmpeg # not ffmpreg, the coolest video conversion tool!
imagemagick # photoshop what??
ffpb # make ffmpeg encoding... a bit fun
;
inherit (pkgs)
ffmpeg # not ffmpreg, the coolest video conversion tool!
imagemagick # photoshop what??
ffpb # make ffmpeg encoding... a bit fun
;
};
in lib.mkMerge (map (user: {
${user}.packages = packages;
}) users);
in userLib.mkUserPackages config.my.toggleUsers.shell packages;
};
}

View File

@@ -12,9 +12,9 @@ in
options.my.shell.tools.enable = lib.mkEnableOption "shell tools and utilities";
config = lib.mkIf config.my.shell.tools.enable {
home-manager.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
in lib.mkMerge (map (user: {
${user}.programs = {
userLib = import ../lib.nix { inherit lib; };
in userLib.mkHomeManagerUsers config.my.toggleUsers.shell (user: {
programs = {
hstr.enable = true;
htop = {
enable = true;
@@ -88,7 +88,7 @@ in
fi
'';
};
}) users);
});
programs = {
starship.enable = true;
tmux.enable = true;
@@ -99,7 +99,7 @@ in
};
};
users.users = let
users = if lib.isString config.my.toggleUsers.shell then [ config.my.toggleUsers.shell ] else config.my.toggleUsers.shell;
userLib = import ../lib.nix { inherit lib; };
packages = builtins.attrValues {
inherit (pkgs)
ripgrep # modern grep
@@ -115,9 +115,7 @@ in
rmlint # amazing dupe finder that integrates well with BTRFS
;
};
in lib.mkMerge (map (user: {
${user}.packages = packages;
}) users);
in userLib.mkUserPackages config.my.toggleUsers.shell packages;
environment.variables = {
HISTFILE = "\${XDG_STATE_HOME}/bash/history";
LESSHISTFILE = "-";