diff --git a/src/nix/eval.nix b/src/nix/eval.nix index 6c9c052..a01f328 100644 --- a/src/nix/eval.nix +++ b/src/nix/eval.nix @@ -256,13 +256,18 @@ let }; }; - flakeToHive = flakeUri: let - flake = builtins.getFlake flakeUri; - hive = if flake.outputs ? colmena then flake.outputs.colmena else throw "Flake must define outputs.colmena."; - in hive; + uncheckedHive = let + flakeToHive = flakeUri: let + flake = builtins.getFlake flakeUri; + hive = if flake.outputs ? colmena then flake.outputs.colmena else throw "Flake must define outputs.colmena."; + in hive; - uncheckedHive = - if rawHive != null then rawHive + rawToHive = 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 throw "Either an attribute set or a flake URI must be specified."; diff --git a/src/nix/tests/mod.rs b/src/nix/tests/mod.rs index dfbc942..f7384d3 100644 --- a/src/nix/tests/mod.rs +++ b/src/nix/tests/mod.rs @@ -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; + }; + } + "#); +}