Colmena - How to push a flake input into the individual nodes?

I have a flake-based Colmena setup which I’m pretty happy with. However, there is one thing that has been causing me problems which is how to get an input from the outer flake into the individual hosts (outputs.colmena.machine-a in this case).

A stripping down version of what I’m asking for is below:

# flake.nix
{
  inputs.fh.url = "https://flakehub.com/f/DeterminateSystems/fh/*.tar.gz";

  outputs = inputs @ {self, fh, ...}: let
    system = "x86_64-linux";
    pkgs = import inputs.nixpkgs {inherit system;};
  in rec {
    colmena = {
      # How do I get machine-a.nix to have `fh` as an input?
      machine-a = import ./machine-a.nix;
    };
  }
}

# machine-a.nix
inputs @ {config, pkgs, ...}: let
  system = "x86_64-linux";
in {
  environment.systemPackages = [
    inputs.fh.packages."${system}".default
  ]
};

I tried a couple of things that don’t seem to work:

  • machine-a = import ./machine-a.nix { inherit (inputs) fh; }
  • machine-a = import ./machine-a.nix { inherit fh; }
      machine-a = {lib, ...}: {
        inherit fh;

        imports = [
          ./hosts/machine-a/default.nix
        ];
      };

There were more, I’ve been trying this off and on for about four months. Any help would be greatly appreciated.

Thank you!

You could for example use meta.specialArgs. This allows injecting anything you want into module function arguments. In your stripped down example:

# flake.nix
{
  inputs.fh.url = "https://flakehub.com/f/DeterminateSystems/fh/*.tar.gz";

  outputs = inputs @ {self, fh, ...}: let
    system = "x86_64-linux";
    pkgs = import inputs.nixpkgs {inherit system;};
  in rec {
    colmena = {
      meta.specialArgs.inputs = inputs;
      # or: meta.specialArgs = { inherit fh; ... };

      machine-a = import ./machine-a.nix;
    };
  }
}

# machine-a.nix
{config, pkgs, inputs, ...}: let
  system = "x86_64-linux";
in {
  environment.systemPackages = [
    inputs.fh.packages."${system}".default
  ]
};

Documentation

Thank you very much, that was exactly what I needed.