From 6933014d75cd0a970316ce3edeac7352e64a3cbc Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 11 May 2024 21:35:13 +0200 Subject: [PATCH] Streamline creation of user modules --- flake.nix | 30 +++++++++++++----------------- lib/configuration.nix | 30 +++++++----------------------- lib/utils/user-module.nix | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 lib/utils/user-module.nix diff --git a/flake.nix b/flake.nix index b95bacf..c2f6f80 100644 --- a/flake.nix +++ b/flake.nix @@ -126,24 +126,20 @@ "${username}@${hostname}" = home-manager.lib.homeManagerConfiguration { modules = let - getUserConfig = pkgs.callPackage (import ./lib/utils/user-config.nix); - userConfigPath = getUserConfig { inherit hostname username; }; - in [ - ( - { pkgs, ... }: { - config._module.args = { - machine = machine // { - name = hostname; - config = machineConfig; - }; + getUserModule = pkgs.callPackage (import ./lib/utils/user-module.nix); + in + getUserModule { + machine = machine // { + name = hostname; + config = machineConfig; + }; - user = { - name = username; - } // user; - }; - }) - sops-nix.homeManagerModules.sops - ] ++ (lib.optional (userConfigPath != null) userConfigPath); + user = { + name = username; + } // user; + } ++ [ + sops-nix.homeManagerModules.sops + ]; }; }) machineConfig.users) diff --git a/lib/configuration.nix b/lib/configuration.nix index 4fef7ff..1e2f16a 100644 --- a/lib/configuration.nix +++ b/lib/configuration.nix @@ -37,29 +37,13 @@ users = lib.attrsets.concatMapAttrs (username: user: let - hostname = machine.name; - getUserConfig = pkgs.callPackage (import ./utils/user-config.nix); - configPath = getUserConfig { inherit hostname username; }; - in - if (configPath != null) - then { - ${username} = { pkgs, ... }: { - imports = [ - configPath - ]; - - config = { - _module.args = { - inherit machine; - - user = { - name = username; - } // user; - }; - }; - }; - } - else {}) + getUserModule = pkgs.callPackage (import ./utils/user-module.nix); + in { + ${username} = (getUserModule { + inherit machine; + user = { name = username; } // user; + }); + }) machine.config.users; }; diff --git a/lib/utils/user-module.nix b/lib/utils/user-module.nix new file mode 100644 index 0000000..83a77bf --- /dev/null +++ b/lib/utils/user-module.nix @@ -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 + ; + }; + }; + } \ No newline at end of file