From bd048e98d8067b98090ad5df844122df050f33e5 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 18 Sep 2022 17:27:46 -0600 Subject: [PATCH] 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. --- flake.nix | 5 +++++ src/nix/hive/eval.nix | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index a732e85..cb6cb9e 100644 --- a/flake.nix +++ b/flake.nix @@ -100,6 +100,11 @@ inherit (colmenaOptions) deploymentOptions metaOptions; inherit (colmenaModules) keyChownModule keyServiceModule; }; + + lib.makeHive = rawHive: import ./src/nix/hive/eval.nix { + inherit rawHive colmenaOptions colmenaModules; + hermetic = true; + }; }; nixConfig = { diff --git a/src/nix/hive/eval.nix b/src/nix/hive/eval.nix index e1621fb..c54ea74 100644 --- a/src/nix/hive/eval.nix +++ b/src/nix/hive/eval.nix @@ -44,7 +44,14 @@ let modules = [ colmenaOptions.metaOptions uncheckedUserMeta ]; }).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 = if !hermetic && userMeta.nixpkgs == null @@ -174,8 +181,8 @@ let in rec { # Exported attributes - # - # Functions are intended to be called with `nix-instantiate --eval --json` + __schema = "v0"; + nodes = listToAttrs (map (name: { inherit name; value = evalNode name (configsFor name); }) nodeNames); toplevel = lib.mapAttrs (_: v: v.config.system.build.toplevel) nodes; deploymentConfig = lib.mapAttrs (_: v: v.config.deployment) nodes;