Accessing flake outputs in the flake itself

For future reference: As extraArgs is being deprecated I am now using the NixOS option config._module.args like this:

{ inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  outputs = { self, nixpkgs, ... }: {
    nixosConfigurations.my-computer = nixpkgs.lib.nixosSystem {
      modules = [
        ./file1.nix ./file2.nix ./gui.nix
	    { config._module.args = { flake = self; }; }
      ];
    };
  }
}

Sadly the NixOS option config._module.args (or even config._module orconfig) is not documented in the NixOS options.

The code for it seems to be in lib/module.nix.

3 Likes