Merge pull request #266 from Pacman99/extract-builds

pass builderArgs to config and extract builds
This commit is contained in:
Pacman99 2021-05-01 17:44:44 -07:00 committed by GitHub
commit 378107fd03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 22 deletions

View file

@ -79,7 +79,7 @@
"utils": "utils_2" "utils": "utils_2"
}, },
"locked": { "locked": {
"narHash": "sha256-TQvd6TvSuT0sJCLlGsV65YjB+nIfDdDKZ1F94pCfkTw=", "narHash": "sha256-oTiKYoR210VwjomzfSn/pCJ3immdUDRUPbYTDGaPFn8=",
"path": "./lib", "path": "./lib",
"type": "path" "type": "path"
}, },

View file

@ -57,6 +57,7 @@
externalModules = [ externalModules = [
ci-agent.nixosModules.agent-profile ci-agent.nixosModules.agent-profile
home.nixosModules.home-manager home.nixosModules.home-manager
./modules/customBuilds.nix
]; ];
}; };
hosts = nixos.lib.mkMerge [ hosts = nixos.lib.mkMerge [

View file

@ -4,9 +4,10 @@ nixosConfigurations:
with lib; with lib;
let let
mkHomes = host: config: mkHomes = hostName: host:
mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) mapAttrs' (user: v: nameValuePair "${user}@${hostName}" v.home)
config.config.system.build.homes; # So this function is useful for non-devos hosts
(host.config.system.build.homes or host.config.home-manager.users);
hmConfigs = mapAttrs mkHomes nixosConfigurations; hmConfigs = mapAttrs mkHomes nixosConfigurations;

View file

@ -64,7 +64,10 @@ lib.systemFlake (lib.mergeAny
hostDefaults = lib.mergeAny hostDefaults { hostDefaults = lib.mergeAny hostDefaults {
specialArgs.suites = cfg.nixos.suites; specialArgs.suites = cfg.nixos.suites;
modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; 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; nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules;

View file

@ -43,6 +43,7 @@
_module.args = { _module.args = {
inherit self; inherit self;
devlib = lib;
hosts = builtins.mapAttrs (_: host: host.config) hosts = builtins.mapAttrs (_: host: host.config)
(removeAttrs self.nixosConfigurations [ config.networking.hostName ]); (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;
}
];
};
} }

View file

@ -23,11 +23,9 @@ let
nixosTesting = nixosTesting =
(import "${toString pkgs.path}/nixos/lib/testing-python.nix" { (import "${toString pkgs.path}/nixos/lib/testing-python.nix" {
inherit (pkgs) system; inherit (pkgs) system;
inherit (host.config.lib) specialArgs; inherit (host.config.lib.builderArgs) specialArgs;
inherit pkgs; inherit pkgs;
extraConfigurations = [ extraConfigurations = host._module.args.modules;
host.config.lib.testModule
];
}); });
in in
test: test:

29
modules/customBuilds.nix Normal file
View file

@ -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;
};
}