forked from DGNum/colmena
eval.nix: Support specifying a list of configs
This commit is contained in:
parent
bc3450b3ce
commit
cdbb69617f
2 changed files with 32 additions and 4 deletions
|
@ -302,6 +302,13 @@ let
|
|||
};
|
||||
in mergedHive // meta;
|
||||
|
||||
configsFor = node: let
|
||||
nodeConfig = hive.${node};
|
||||
in
|
||||
assert lib.assertMsg (!elem node reservedNames) "\"${node}\" is a reserved name and cannot be used as the name of a node";
|
||||
if typeOf nodeConfig == "list" then nodeConfig
|
||||
else [ nodeConfig ];
|
||||
|
||||
mkNixpkgs = configName: pkgConf: let
|
||||
uninitializedError = typ: ''
|
||||
Passing ${typ} as ${configName} is no longer accepted with Flakes.
|
||||
|
@ -348,7 +355,7 @@ let
|
|||
lib = pkgs.lib;
|
||||
reservedNames = [ "defaults" "network" "meta" ];
|
||||
|
||||
evalNode = name: config: let
|
||||
evalNode = name: configs: let
|
||||
npkgs =
|
||||
if hasAttr name hive.meta.nodeNixpkgs
|
||||
then mkNixpkgs "meta.nodeNixpkgs.${name}" hive.meta.nodeNixpkgs.${name}
|
||||
|
@ -436,8 +443,7 @@ let
|
|||
keyChownModule
|
||||
deploymentOptions
|
||||
hive.defaults
|
||||
config
|
||||
] ++ (import (npkgs.path + "/nixos/modules/module-list.nix"));
|
||||
] ++ configs ++ (import (npkgs.path + "/nixos/modules/module-list.nix"));
|
||||
specialArgs = hive.meta.specialArgs // {
|
||||
inherit name nodes;
|
||||
modulesPath = npkgs.path + "/nixos/modules";
|
||||
|
@ -452,7 +458,7 @@ let
|
|||
|
||||
nodes = listToAttrs (map (name: {
|
||||
inherit name;
|
||||
value = evalNode name hive.${name};
|
||||
value = evalNode name (configsFor name);
|
||||
}) nodeNames);
|
||||
|
||||
toplevel = lib.mapAttrs (name: eval: eval.config.system.build.toplevel) nodes;
|
||||
|
|
|
@ -200,6 +200,28 @@ fn test_parse_unknown_option() {
|
|||
"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_config_list() {
|
||||
TempHive::valid(r#"
|
||||
with builtins;
|
||||
{
|
||||
host-a = [
|
||||
{
|
||||
time.timeZone = "America/Los_Angeles";
|
||||
}
|
||||
{
|
||||
deployment.tags = [ "some-tag" ];
|
||||
}
|
||||
];
|
||||
host-b = { name, nodes, ... }:
|
||||
assert length (attrNames nodes) == 2;
|
||||
assert nodes.host-a.config.time.timeZone == "America/Los_Angeles";
|
||||
assert elem "some-tag" nodes.host-a.config.deployment.tags;
|
||||
{};
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_key_text() {
|
||||
TempHive::valid(r#"
|
||||
|
|
Loading…
Reference in a new issue