Option pkgs does not exist in spread configuration

Hi!

I recently discovered how to manage configuration for multiple devices with nix flakes and I came up with the idea of splitting my configuration.nix into different files. I wanted them to use inherit to use my flake packages but I get The option 'inputs' does not exist error. How do we import use flake inputs across multiple files? Isn’t inherit keyword enough for that?

  • flake.nix*
{
  description = "Waves in a room";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-wsl.url = "github:nix-community/NixOS-WSL/main";
  };

  outputs = { self, nixpkgs, ...}@inputs:{
    nixosConfigurations.laptop = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {inherit inputs;};
      modules = [ ./laptop/configuration.nix ];
    };
    nixosConfigurations."desktop" = nixpkgs.lib.nixosSystem {
      specialArgs = { inherit inputs; };
      modules = [ ./wsl/configuration.nix ];
    };
  };
}

*./laptop/configuration.nix *

{ inputs, ... }:

{
  imports =
    [ 
      ./hardware-configuration.nix
      ../users/wavesinaroom.nix {inherit inputs;}
      ../common/shared.nix {inherit inputs;}
    ];

# My configuration
}

I’ve got really good support from the community so far and I’m working hard to learn more about it cause I love it. If you post an answer, can you please recommend me the topic I should read/review so I can understand what’s behind your answer please? Troubleshooting is rewarding indeed but getting why this work is extremely valuable for me :slight_smile:

Delete the {inherit inputs;} here.

While modules take arguments, they’re passed in through the module system from the _module.args option, not at “calltime”. _module.args in turn is intialized with everything you put in specialArgs, so the modules already get your inputs and you don’t need to do anything else.

The error message you get in turn can be explained by understanding that {inherit inputs;}, which translates to:

{
  inputs = inputs;
}

Is a valid NixOS module. Since you add that to the imports list, the module system attempts to treat it as a module, and then tells you that there is no inputs option, because you’ve asked it to set the inputs option.

You probably actually meant something like this:

imports =
    [ 
      ./hardware-configuration.nix
      (../users/wavesinaroom.nix {inherit inputs;})
      (../common/shared.nix {inherit inputs;})
    ];

But that’s also nonsensical because paths aren’t functions. The error will just be a bit less confusing.

You’re struggling with basic nix syntax and the concept of the module system.

I’m not sure reading will help much, because you’ve built a false mental model of how nix code is evaluated, but there is good documentation on nix.dev for the basic syntax.

There’s also less clear documentation on the module system there. It might help, but you’ll have to understand that NixOS module code follows nix syntax, but layers some additional abstractions on top.

Don’t worry, though, these are topics that frequently confuse newcomers. I had similar issues when I got started, it’s very nonobvious where the module args come from at first. It’s just about building the right mental model.

The notable things I don’t think you fully understand are:

  • That lists elements are not evaluated, so function args get treated as list elements if not parenthesized
  • That imports can take paths or modules defined inline
  • What inherits does
  • How the module system synthesizes the module arguments
    • This in turn probably means you understand nothing about the module system so far
3 Likes

Many thanks for taking time to answer my question! I liked your feedback as well.

My goal writing my question was going beyond troubleshooting to see what I needed learn. You helped me a lot discovering that :slight_smile:

Cheers!