Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass builderArgs to config and extract builds #266

Merged
merged 1 commit into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
externalModules = [
ci-agent.nixosModules.agent-profile
home.nixosModules.home-manager
./modules/customBuilds.nix
];
};
hosts = nixos.lib.mkMerge [
Expand Down
7 changes: 4 additions & 3 deletions lib/devos/mkHomeConfigurations.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion lib/mkFlake/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

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

6 changes: 2 additions & 4 deletions lib/pkgs-lib/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions modules/customBuilds.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}