flake.nix: Add lib.makeHive

Ground work to make the evaluation logic more clearly separated from
the deployment logic.

The `colmenaHive` output will be the integration point between the two
halves.
This commit is contained in:
Zhaofeng Li 2022-09-18 17:27:46 -06:00
parent 95be6686ae
commit bd048e98d8
2 changed files with 15 additions and 3 deletions

View file

@ -100,6 +100,11 @@
inherit (colmenaOptions) deploymentOptions metaOptions; inherit (colmenaOptions) deploymentOptions metaOptions;
inherit (colmenaModules) keyChownModule keyServiceModule; inherit (colmenaModules) keyChownModule keyServiceModule;
}; };
lib.makeHive = rawHive: import ./src/nix/hive/eval.nix {
inherit rawHive colmenaOptions colmenaModules;
hermetic = true;
};
}; };
nixConfig = { nixConfig = {

View file

@ -44,7 +44,14 @@ let
modules = [ colmenaOptions.metaOptions uncheckedUserMeta ]; modules = [ colmenaOptions.metaOptions uncheckedUserMeta ];
}).config; }).config;
mergedHive = removeAttrs (defaultHive // uncheckedHive) [ "meta" "network" ]; mergedHive =
assert lib.assertMsg (!(uncheckedHive ? __schema)) ''
You cannot pass in an already-evaluated Hive into the evaluator.
Hint: Use the `colmenaHive` output instead of `colmena`.
'';
removeAttrs (defaultHive // uncheckedHive) [ "meta" "network" ];
meta = { meta = {
meta = meta =
if !hermetic && userMeta.nixpkgs == null if !hermetic && userMeta.nixpkgs == null
@ -174,8 +181,8 @@ let
in rec { in rec {
# Exported attributes # Exported attributes
# __schema = "v0";
# Functions are intended to be called with `nix-instantiate --eval --json`
nodes = listToAttrs (map (name: { inherit name; value = evalNode name (configsFor name); }) nodeNames); nodes = listToAttrs (map (name: { inherit name; value = evalNode name (configsFor name); }) nodeNames);
toplevel = lib.mapAttrs (_: v: v.config.system.build.toplevel) nodes; toplevel = lib.mapAttrs (_: v: v.config.system.build.toplevel) nodes;
deploymentConfig = lib.mapAttrs (_: v: v.config.deployment) nodes; deploymentConfig = lib.mapAttrs (_: v: v.config.deployment) nodes;