Where does config.system.nixos.release get defined?

Context, one of my NixOS configurations did not define system.stateVersion, so quite helpfully the warning message for nix-build pointed me to this documentation: https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion (TIL the risks of not explicitly setting state.systemVersion). I still have a few gaps in my understanding though…

I’m pinning nixpkgs in my repository, so I must have falsely assumed that config.system.nixos.release (which system.stateVersion defaults to) would be pinned, but it seems like it isn’t.

Can someone help me understand why pinning nixpkgs doesn’t help me here?

Where does config.system.nixos.release get defined?

You can see that it is defined in the same module in the Configuration Options appendix.

Pinning nixpkgs will make the default values of the options predictable – but that is not the issue. If you bump the pinned Nixpkgs, the stateVesion could change without your knowing and break your system.

but that is not the issue. If you bump the pinned Nixpkgs, the stateVesion could change without your knowing and break your system.

In my case, I’m not sure this is what happened. I got two different configurations when running nix-build on two different machines:

  • Machine A: nix-build (Nix) 2.3.16: used 21.11
  • Machine B: nix-build (Nix) 2.8.1: warned about defaulting to 22.11 (breaking changes)

I got different result without bumping nixpkgs. It’s still unclear to me why my pinned nixpkgs didn’t help me here.

Are you sure you have nixpkgs pinned? What pinning method did you use and how are you rebuilding your systems?

Are you sure you have nixpkgs pinned? What pinning method did you use

Pretty sure. I’m using niv to pin nixos-unstable, nixos-21.11.

how are you rebuilding your systems?

nix-build /path/to/repo -A path.to.nixos.system

Well, as you can see from the definition:

  1. nixpkgs/version.nix at 87d9c84817d7be81850c07e8f6a362b1dfc30feb · NixOS/nixpkgs · GitHub
  2. nixpkgs/version.nix at 87d9c84817d7be81850c07e8f6a362b1dfc30feb · NixOS/nixpkgs · GitHub
  3. nixpkgs/trivial.nix at 87d9c84817d7be81850c07e8f6a362b1dfc30feb · NixOS/nixpkgs · GitHub
  4. nixpkgs/.version at 87d9c84817d7be81850c07e8f6a362b1dfc30feb · NixOS/nixpkgs · GitHub

It gets it from Nixpkgs’s lib so if the two configurations set pinned Nixpkgs version and configuration is the same, there must be some impurity.