Article: make flakes use same nixpkgs as NixOS

I read this article by @Solene. First of all thanks Solene for writing that up and contributing. I’m stumbling over more and more of your work and all of it is pure quality. Sadly, it didn’t work for me.

$ sudo nixos-rebuild switch --builders '' --flake '/home/jan/devel/nixos/#conix' --show-trace
error: cannot find flake 'flake:inputs' in the flake registries

       … while updating the flake input 'inputs'

       … while updating the lock file of flake 'path:/home/jan/devel/nixos?narHash=sha256-hDVusVsc12rDn2C%2fpEk8tSF6A3bwqf4%2fjUdjX+NFI64='

Maybe the fine people here could give me a hint or two on what’s going wrong.

{
  description = "confus' NixOS configuration, modules and packages";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-22.05";
    nixunstable.url = "nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware";
  };

  outputs = { self, nixpkgs, nixunstable, nixos-hardware,
    inputs  # if not here: " undefined variable 'inputs' "
  }: {
    nixosConfigurations = {

      conix = nixunstable.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        modules = [
          ./machines/co.nix
        ];
      };

      # ...

    };
  };
}
1 Like

Close but no cigar, you want:

outputs = {self, nixpkgs, nixunstable, nixos-hardware, ...}@inputs:

That syntax means "put all the arguments, even the ones not explicitly named, in inputs". The ... is admittedly superfluous here, you could skip it, that’s only required if there are inputs you don’t want to explicitly give a name.

Alternatively you can also just explicitly go inputs = {inherit self nixpkgs nixunstable nixos-hardware;}; in the specialArgs bit.

Nix will automatically look at your “flake registry” (you can see its contents with nix registry list) to find any arguments to the outputs function not defined in inputs. And since your outputs ask for an inputs variable, it looks for something called inputs in your registry. Hence you end up with that error.

1 Like

I find it extremely hard to give instructions to make changes on flakes.nix files and that “first line” of nix files :confused:

Thanks Solene, and yes, I did add the inputs. Basically what TLATER wrote just above fixed my problem and it seems to work now.

Just for the sake of completeness, I could of course, just have specialArgs = { inherit nixunstable; }; and then passed nixunstable as a parameter in co.nix and used that in the nix.registry.nixpkgs.flake = nixunstable; as well as the nix.nixPath = ...; lines, or have used let mynix = nixunstable; in { nixosConfigurations = ..., so it’s guaranteed to be the same.

1 Like

And thanks to @TLATER I understood the @inputs syntax :smiley: