I have a custom NixOS module that I use in my flake and I have an issue with the nixpkgs
input not being respected.
My module flake has the following (shortened for brevity):
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
};
outputs =
{ self
, nixpkgs
}:
{
homeManagerModule = import ./modules/home-manager;
nixosModules = {
earth-view = import ./modules/nixos;
default = self.nixosModules.earth-view;
};
};
}
As you can see, I specifically set nixpkgs
input to be on nixos-23.11
. However, when I use the module in my nix-config flake, it takes the nixpkgs
input defined in my nix-config, not the one defined in the module…
I have to mention that I didn’t use the inputs.nixpkgs.follows
option, so I don’t understand why is this happening? Is it because the module flake uses nixpkgs
for the input name, as does the nix-config flake (and somehow the nixpkgs
defined in nix-config takes precedence)?
In order to work around this, I had to do the following in my nix-config flake:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-23.11";
earth-view = {
url = "github:nicolas-goudry/earth-view";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, ... }@inputs: {
nixosConfigurations = {
g-xps = let
system = "x86_64-linux";
in inputs.nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = inputs;
modules = [
./hosts/g-xps
{
_module.args = {
pkgs-stable = inputs.nixpkgs-stable.legacyPackages.${system};
};
}
];
};
};
};
}
(I tried using inputs.nixpkgs.follows = "nixpkgs-stable";
but it didn’t work…)
I updated the custom module definition to do this:
{ config, lib, pkgs, pkgs-stable ? pkgs, ... }: {}
Is it possible to force the module to use the nixpkgs
input defined in its flake, while still allowing users to use inputs.nixpkgs.follows
to override the default?
Aside from the _module.args
option I couldn’t find anything relevant in the Nix docs. And it seems to be user-oriented, not module developer oriented.