I recently began to work on my NixOS configuration and just ran into a problem I can’t seem to find a solution for.
I’m using NixOS flakes and am passing down inputs
as specialArgs down to my sub-modules. To my understanding, all child-modules should be able to import inputs
and then use it.
Here is an excerpt from my configuration:
flake.nix
{
...
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.05";
};
outputs = inputs @ { self, nixpkgs, nixpkgs-stable, home-manager, ... }:
let
system = "x86_64-linux";
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
commonArgs = { # <-- Creating a variable for storing my specialArgs
inherit inputs pkgs-stable;
};
in {
nixosConfigurations = {
ideapad = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = commonArgs; # <-- Passing down specialArgs to all sub-modules
modules = [
./hosts/ideapad/configuration.nix
...
];
};
};
};
}
in my configuration.nix
I import system/base/default.nix
and from there nix.nix
.
Basically like:
{ ... }:
{
imports = [
./system/base/default.nix
];
}
{ ... }:
{
imports = [
./nix.nix
];
}
Now in my nix.nix
file I try to reference inputs.nixpkgs.<...>
.
{ lib, inputs, ... }:
{
# Enable Nix Flakes
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Allow unfree packages from stable and unstable branch
inputs.nixpkgs.config.allowUnfree = lib.mkForce true;
inputs.nixpkgs-stable.config.allowUnfree = lib.mkForce true;
...
}
But when trying to rebuild my system configuration I get following error:
building the system configuration...
error:
… while calling the 'seq' builtin
at /nix/store/rljkm6h18fjvavm6l17jiil8glphc44f-source/lib/modules.nix:322:18:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
… while calling the 'throw' builtin
at /nix/store/rljkm6h18fjvavm6l17jiil8glphc44f-source/lib/modules.nix:298:18:
297| ''
298| else throw baseMsg
| ^
299| else null;
# ERROR BEGINS HERE
error: The option `inputs' does not exist. Definition values:
- In `/nix/store/vqwpv723z9278kpgni969k3rswapgqwf-source/modules/system/base/nix.nix':
{
nixpkgs = {
config = {
allowUnfree = {
_type = "override";
...
To my understanding inputs
should also be accessible to nix.nix
but clearly it isn’t. Is this a misunderstanding from my side or am I just blatantly not seeing where my error lies?
I greatly appreciate any help, thank you!