colmena icon indicating copy to clipboard operation
colmena copied to clipboard

Evaluate whole configurations ?

Open rgrunbla opened this issue 2 years ago • 5 comments

Hello,

I'd like to be able to evaluate the whole colmena configuration using colmena eval. Currently, it seems it's not working:

$ cat eval.nix

{ nodes, pkgs, lib, ... }:
lib.attrsets.mapAttrs (k: v: v.config) nodes

$ colmmena eval eval.nix

error: attribute 'cycle' missing

       at /nix/store/h5rmlfv5gnpjgc10xf6n6hkw0dvb997p-source/nixos/modules/tasks/filesystems.nix:230:119:

          229|       { assertion = ! (fileSystems' ? cycle);
          230|         message = "The ‘fileSystems’ option can't be topologically sorted: mountpoint dependency path ${ls " -> " fileSystems'.cycle} loops to ${ls ", " fileSystems'.loops}";
             |                                                                                                                       ^
          231|       }
[ERROR] -----
[ERROR] Operation failed with error: Nix exited with error code: 1
[…]

The flake.nix is below. My guess is there is a problem nix side, so, that might not be fixable.

Rémy

Flake.nix:

{
  description = "Sisyphe system configuration";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
    colmena.url = "github:zhaofengli/colmena";
  };

  outputs = { self, nixpkgs, colmena }: {
    colmena = {
      meta = { nixpkgs = import nixpkgs { system = "x86_64-linux"; }; };

      test = { name, nodes, pkgs, ... }: {
        deployment = { };
      };
    };

    devShell.x86_64-linux = with import nixpkgs { system = "x86_64-linux"; };
      mkShell {
        buildInputs = [ colmena.packages.x86_64-linux.colmena ];
      };
  };
}

rgrunbla avatar Dec 01 '21 16:12 rgrunbla

I don't think it's possible to evaluate the entire configuration in JSON, since many parts of the configuration depend on lazy evaluation. In this case, the message attribute of the assertion should only be evaluated if the assertion fails, and it depends on an attribute that is only present when there is a cycle.

However, if you are looking to build the system profile outside Colmena, you can use --instantiate:

$ colmena eval --instantiate -E '{ nodes, lib, ... }: nodes.alpha.config.system.build.toplevel'
/nix/store/adxaxn345yyibhwzxyqliama29j35dfm-nixos-system-alpha-21.11pre-git.drv

zhaofengli avatar Dec 01 '21 19:12 zhaofengli

I'm not exactly looking to build the system profile outside colmena, or, maybe, not in the classical way.

I use deployment.keys to deploy nix files (the same one used to build the configuration of the machines with colmena) in /etc/nixos on the machine, allowing me to be able to rebuild-switch from inside the managed machine. This works because right now, my nix files do not contain references to nodes attributes, and are "flat". My goal is to be able to evaluate such nix files to somehow remove dependencies to nodes (evaluate such files) to be able to rebuild the nodes after having them deployed with colmena.

On another subject, is there some IRC channel / Matrix channel where to exchange around colmena ?

rgrunbla avatar Dec 01 '21 19:12 rgrunbla

Matrix channel https://matrix.to/#/#nixops:nixos.org

You could always add your machine configurations as an overlay, and then access properties of other machines with pkgs.<your-overlay>.<other-host>.config.<property>

buckley310 avatar Jan 04 '22 18:01 buckley310

Note that now there is also a new channel at #colmena:nixos.org for Colmena-specific stuff.

zhaofengli avatar Jan 04 '22 22:01 zhaofengli

I have to ask, if your machines are all centrally managed, what's the reason behind the local rebuilds?

buckley310 avatar Jan 06 '22 18:01 buckley310