Streamline creation of user modules

This commit is contained in:
Manuel Thalmann 2024-05-11 21:35:13 +02:00
parent 8ca8b885e2
commit 6933014d75
3 changed files with 38 additions and 40 deletions

View file

@ -126,12 +126,9 @@
"${username}@${hostname}" = home-manager.lib.homeManagerConfiguration { "${username}@${hostname}" = home-manager.lib.homeManagerConfiguration {
modules = modules =
let let
getUserConfig = pkgs.callPackage (import ./lib/utils/user-config.nix); getUserModule = pkgs.callPackage (import ./lib/utils/user-module.nix);
userConfigPath = getUserConfig { inherit hostname username; }; in
in [ getUserModule {
(
{ pkgs, ... }: {
config._module.args = {
machine = machine // { machine = machine // {
name = hostname; name = hostname;
config = machineConfig; config = machineConfig;
@ -140,10 +137,9 @@
user = { user = {
name = username; name = username;
} // user; } // user;
}; } ++ [
})
sops-nix.homeManagerModules.sops sops-nix.homeManagerModules.sops
] ++ (lib.optional (userConfigPath != null) userConfigPath); ];
}; };
}) })
machineConfig.users) machineConfig.users)

View file

@ -37,29 +37,13 @@
users = users =
lib.attrsets.concatMapAttrs (username: user: lib.attrsets.concatMapAttrs (username: user:
let let
hostname = machine.name; getUserModule = pkgs.callPackage (import ./utils/user-module.nix);
getUserConfig = pkgs.callPackage (import ./utils/user-config.nix); in {
configPath = getUserConfig { inherit hostname username; }; ${username} = (getUserModule {
in
if (configPath != null)
then {
${username} = { pkgs, ... }: {
imports = [
configPath
];
config = {
_module.args = {
inherit machine; inherit machine;
user = { name = username; } // user;
user = { });
name = username; })
} // user;
};
};
};
}
else {})
machine.config.users; machine.config.users;
}; };

18
lib/utils/user-module.nix Normal file
View file

@ -0,0 +1,18 @@
{ lib, pkgs, machine, user }:
let
hostname = machine.name;
username = user.name;
getUserConfig = pkgs.callPackage (import ./user-config.nix);
userConfigPath = getUserConfig { inherit hostname username; };
in { pkgs, ... }: {
imports = lib.optional (userConfigPath != null) userConfigPath;
config = {
_module.args = {
inherit
machine
user
;
};
};
}