From e98e595704f2635f2b0fc9ffc999ae603ddaad24 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Wed, 28 Apr 2021 11:30:04 -0700 Subject: [PATCH] pass builderArgs to config and extract builds have mkHomeConfiguration create its own custom build within the function create a externalModule for customBuilds so its easy to add more --- flake.lock | 2 +- flake.nix | 1 + lib/devos/mkHomeConfigurations.nix | 7 ++++--- lib/mkFlake/default.nix | 5 ++++- lib/modules.nix | 14 +------------- lib/pkgs-lib/tests/default.nix | 6 ++---- modules/customBuilds.nix | 29 +++++++++++++++++++++++++++++ 7 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 modules/customBuilds.nix diff --git a/flake.lock b/flake.lock index 27fecfbf..484e3011 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", + "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=", "path": "./lib", "type": "path" }, diff --git a/flake.nix b/flake.nix index 386bd327..41a83a9f 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ externalModules = [ ci-agent.nixosModules.agent-profile home.nixosModules.home-manager + ./modules/customBuilds.nix ]; }; hosts = nixos.lib.mkMerge [ diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix index 3a07ba82..95affc26 100644 --- a/lib/devos/mkHomeConfigurations.nix +++ b/lib/devos/mkHomeConfigurations.nix @@ -4,9 +4,10 @@ nixosConfigurations: with lib; let - mkHomes = host: config: - mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) - config.config.system.build.homes; + mkHomes = hostName: host: + mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home) + # So this function is useful for non-devos hosts + (host.config.system.build.homes or host.config.home-manager.users); hmConfigs = mapAttrs mkHomes nixosConfigurations; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index e5862d39..ed99db0f 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -64,7 +64,10 @@ lib.systemFlake (lib.mergeAny hostDefaults = lib.mergeAny hostDefaults { specialArgs.suites = cfg.nixos.suites; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; - builder = os.devosSystem { inherit self inputs; }; + builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { + # So modules and functions can create their own version of the build + modules = [ { lib.builderArgs = args; } ]; + }); }; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; diff --git a/lib/modules.nix b/lib/modules.nix index 6e2a3525..60e29719 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -43,6 +43,7 @@ _module.args = { inherit self; + devlib = lib; hosts = builtins.mapAttrs (_: host: host.config) (removeAttrs self.nixosConfigurations [ config.networking.hostName ]); }; @@ -111,18 +112,5 @@ }; }; - hmConfig = - { config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }; } diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index 854332fe..e08702ac 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -23,11 +23,9 @@ let nixosTesting = (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { inherit (pkgs) system; - inherit (host.config.lib) specialArgs; + inherit (host.config.lib.builderArgs) specialArgs; inherit pkgs; - extraConfigurations = [ - host.config.lib.testModule - ]; + extraConfigurations = host._module.args.modules; }); in test: diff --git a/modules/customBuilds.nix b/modules/customBuilds.nix new file mode 100644 index 00000000..b9648dca --- /dev/null +++ b/modules/customBuilds.nix @@ -0,0 +1,29 @@ +{ lib, self, devlib, config, modules, channel, ... }: +let + mkBuild = buildModule: + channel.input.lib.nixosSystem (devlib.mergeAny config.lib.builderArgs { + modules = [ buildModule ]; + }); +in +{ + system.build = { + iso = (mkBuild (devlib.modules.isoConfig { + inherit self; + inherit (self) inputs; + fullHostConfig = config; + })).config.system.build.isoImage; + + homes = (mkBuild ({ config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + })).config.home-manager.users; + }; +}