Don't require meta.nixpkgs if meta.nodeNixpkgs is set for the target host(s)
I think it's a little weird to require nixpkgs to be set (because it requires a system set which may change at any point, depending on where you're deploying from). Sure, right now, I may be using x86_64-linux, but I may want to use aarch64-linux or some other arch at any time.
I would expect, if all of the target hosts have a matching nodeNixpkgs entry, that meta.nixpkgs wouldn't be required.
Even better, if it was combined with a deployment.nixpkgs option that replaces the meta.nodeNixpkgs option (EDIT: opened https://github.com/zhaofengli/colmena/issues/55 for this).
I may be able to work on this, if this is desired by more than just me.
One workaround I just found is setting meta.nixpkgs to be a set that only contains lib, e.g.:
{
meta = {
nixpkgs = {
lib = inputs.nixpkgs.lib;
};
};
}
and this sidesteps the immediate issue.
Related discussion on #colmena:nixos.org on 2022-02-03:
pacien: By the way, what is meta.nixpkgs used for? Which system should be set for importing nixpkgs there? Should it match the platform of the machine running colmena?
zhaofengli: It should be the platform that you are deploying to, not the one running Colmena itself.
pacien: ok! I'm setting this with nodeNixpkgs explicitly for each node. Would it be possible to make nixpkgs not mandatory in this case?
zhaofengli: Sadly not, because we still rely on some helper functions from lib of the top-level pinned nixpkgs. We could use the ones from an arbitrary nodeNixpkgs but it doesn't seem ideal.
I tried passing only the lib attribute to colmena.meta.nixpkgs as proposed
in the workaround above, but it seems that some packages are also being used
from meta.nixpkgs, as shown in the resulting evaluation error:
❯ colmena build --on box --show-trace
[INFO ] Enumerating nodes...
[INFO ] Selected 1 out of 14 hosts.
box ❌ 0s Evalation failed: Nix exited with error code: 1
[ERROR] Evaluation of box failed. Logs:
[ERROR] error: attribute 'writeScript' missing
[ERROR]
[ERROR] at /tmp/.tmpJlp24p:462:15:
[ERROR]
[ERROR] 461| json = toJSON (lib.attrsets.mapAttrs (k: v: toString v) selected);
[ERROR] 462| builder = pkgs.writeScript "${name}.sh" ''
[ERROR] | ^
[ERROR] 463| #!/bin/sh
[ERROR]
[ERROR] … while evaluating the attribute 'builder' of the derivation 'colmena-hive'
[ERROR]
[ERROR] at /tmp/.tmpJlp24p:459:5:
[ERROR]
[ERROR] 458| in derivation rec {
[ERROR] 459| name = "colmena-${hive.meta.name}";
[ERROR] | ^
[ERROR] 460| system = currentSystem;
[ERROR]
it seems that some packages are also being used
This is no longer the case in the main branch, where we now just evaluate the .drvPaths of system profiles and launch builds for them in parallel.
One workaround I just found is setting
meta.nixpkgsto be a set that only containslib, e.g.:{ meta = { nixpkgs = { lib = inputs.nixpkgs.lib; }; }; }and this sidesteps the immediate issue.
Is the workaround still supposed to work?
I'm seeing the following error
$ colmena build --show-trace
warning: Git tree '/home/dante/roughb/ops/mono' is dirty
[INFO ] Using flake: git+file:///home/dante/roughb/ops/mono
[INFO ] Enumerating nodes...
error: attribute 'path' missing
at /nix/store/2w5hsib3c1dy1ddmag6haz8drllnchsy-source/src/nix/hive/eval.nix:122:26:
121| else nixpkgs;
122| evalConfig = import (npkgs.path + "/nixos/lib/eval-config.nix");
| ^
123|
… while realising the context of a path
at /nix/store/2w5hsib3c1dy1ddmag6haz8drllnchsy-source/src/nix/hive/eval.nix:122:18:
121| else nixpkgs;
122| evalConfig = import (npkgs.path + "/nixos/lib/eval-config.nix");
| ^
123|
… while evaluating 'evalNode'
at /nix/store/2w5hsib3c1dy1ddmag6haz8drllnchsy-source/src/nix/hive/eval.nix:117:20:
116|
117| evalNode = name: configs: let
| ^
118| npkgs =
… from call site
at /nix/store/2w5hsib3c1dy1ddmag6haz8drllnchsy-source/src/nix/hive/eval.nix:186:59:
185|
186| nodes = listToAttrs (map (name: { inherit name; value = evalNode name (configsFor name); }) nodeNames);
| ^
187| toplevel = lib.mapAttrs (_: v: v.config.system.build.toplevel) nodes;
… while evaluating anonymous lambda
at /nix/store/2w5hsib3c1dy1ddmag6haz8drllnchsy-source/src/nix/hive/eval.nix:188:39:
187| toplevel = lib.mapAttrs (_: v: v.config.system.build.toplevel) nodes;
188| deploymentConfig = lib.mapAttrs (_: v: v.config.deployment) nodes;
| ^
189| deploymentConfigSelected = names: lib.filterAttrs (name: _: elem name names) deploymentConfig;
… from call site
[ERROR] -----
[ERROR] Operation failed with error: Child process exited with error code: 1
Hint: Backtrace available - Use `RUST_BACKTRACE=1` environment variable to display a backtrace