Make flake evaluation pure

This seems to be the easiest way to get pure-eval working with
existing evaluation mechinery (nix-instantiate, nix-eval-jobs).

Now `--pure-eval` is forced for flakes with user being able to
add `--impure` as needed.
This commit is contained in:
Zhaofeng Li 2022-08-16 20:15:43 -06:00
parent 092e5848ab
commit 8aca525788
7 changed files with 70 additions and 29 deletions

View file

@ -1,6 +1,6 @@
{ rawHive ? null # Colmena Hive attrset
, flakeUri ? null # Nix Flake URI with `outputs.colmena`
, hermetic ? flakeUri != null # Whether we are allowed to use <nixpkgs>
, rawFlake ? null # Nix Flake attrset with `outputs.colmena`
, hermetic ? rawFlake != null # Whether we are allowed to use <nixpkgs>
, colmenaOptions
, colmenaModules
}:
@ -19,10 +19,8 @@ let
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;
flakeToHive = rawFlake:
if rawFlake.outputs ? colmena then rawFlake.outputs.colmena else throw "Flake must define outputs.colmena.";
rawToHive = rawHive:
if typeOf rawHive == "lambda" || rawHive ? __functor then rawHive {}
@ -30,8 +28,8 @@ let
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.";
else if rawFlake != null then flakeToHive rawFlake
else throw "Either a plain Hive attribute set or a Nix Flake attribute set must be specified.";
uncheckedUserMeta =
if uncheckedHive ? meta && uncheckedHive ? network then