eval.nix: Support autocall for hive configuration

This commit is contained in:
Zhaofeng Li 2021-08-26 19:59:22 -07:00
parent 7cc6552ee3
commit 37b43cd6d7
2 changed files with 34 additions and 6 deletions

View file

@ -256,13 +256,18 @@ let
}; };
}; };
flakeToHive = flakeUri: let uncheckedHive = let
flake = builtins.getFlake flakeUri; flakeToHive = flakeUri: let
hive = if flake.outputs ? colmena then flake.outputs.colmena else throw "Flake must define outputs.colmena."; flake = builtins.getFlake flakeUri;
in hive; hive = if flake.outputs ? colmena then flake.outputs.colmena else throw "Flake must define outputs.colmena.";
in hive;
uncheckedHive = rawToHive = rawHive:
if rawHive != null then rawHive if typeOf rawHive == "lambda" then rawHive {}
else if typeOf rawHive == "set" then rawHive
else throw "The config must evaluate to an attribute set.";
in
if rawHive != null then rawToHive rawHive
else if flakeUri != null then flakeToHive flakeUri else if flakeUri != null then flakeToHive flakeUri
else throw "Either an attribute set or a flake URI must be specified."; else throw "Either an attribute set or a flake URI must be specified.";

View file

@ -405,3 +405,26 @@ fn test_meta_special_args() {
} }
"#); "#);
} }
#[test]
fn test_hive_autocall() {
TempHive::valid(r#"
{
argument ? "with default value"
}: {
borg = { ... }: {
boot.isContainer = true;
};
}
"#);
TempHive::invalid(r#"
{
thisWontWork
}: {
borg = { ... }: {
boot.isContainer = true;
};
}
"#);
}