I had trouble working out how to pin the nixpkgs
registry entry to a release channel. I’m posting it here in case anyone else finds it helpful.
On my system, I want the nixpkgs
flake to refer to the nixos-21.05
channel (flake url: github:NixOS/nixpkgs/nixos-21.05
). But I want this channel to be pinned to a known commit. I want to be able to update this manually.
In order to achieve this, I use the following steps:
-
Starting off, I don’t have any
user
registry entries:$ nix registry list .... global flake:nixpkgs github:NixOS/nixpkgs ...
At this point, the
nixpkgs
flake will refer to themaster
branch ingithub:NixOS/nixpkgs
(which is currently immediately before the 21.11 release):$ nix eval nixpkgs#lib.version "21.11pre-git"
-
First, you need to add an override to make
nixpkgs
refer to thenixos-21.05
branch:$ nix registry add nixpkgs github:NixOS/nixpkgs/nixos-21.05 $ nix registry list user flake:nixpkgs github:NixOS/nixpkgs/nixos-21.05 ... global flake:nixpkgs github:NixOS/nixpkgs ...
-
You then need to pin
github:NixOS/nixpkgs/nixos-21.05
:$ nix registry pin github:NixOS/nixpkgs/nixos-21.05 $ nix registry list user flake:nixpkgs github:NixOS/nixpkgs/nixos-21.05 user github:NixOS/nixpkgs/nixos-21.05 github:NixOS/nixpkgs/1e5c35dfbc8e0ad8c35aa1a6446f442ca1ec5234 ... global flake:nixpkgs github:NixOS/nixpkgs ...
Now, the
nixpkgs
flake will refer to this known-good commit on thenixos-21.05
branch:$ nix eval nixpkgs#lib.version ""21.05pre-git""
When you want to bump the pin to the latest version of nixos-21.05
, you can use the following command:
$ nix registry pin github:NixOS/nixpkgs/nixos-21.05
Note that you must not accidentally pin the nixpkgs
flake. DO NOT DO THIS:
$ nix registry pin nixpkgs
$ nix registry list
user github:NixOS/nixpkgs/nixos-21.05 github:NixOS/nixpkgs/1e5c35dfbc8e0ad8c35aa1a6446f442ca1ec5234
user flake:nixpkgs github:NixOS/nixpkgs/9fcf2a8a2cb0f5b78edc8ec7ca877240e7fe3009
...
global flake:nixpkgs github:NixOS/nixpkgs
...
$ nix eval nixpkgs#lib.version
"21.11pre-git"
You can see that here the nixpkgs
flake is now pointing back at the master
branch. It is unfortunate that Nix doesn’t just “do the right thing” here.
When you want to make the nixpkgs
flake point a more recent release of NixOS (the next version will probably be 21.11), you can use the following command:
$ nix registry add nixpkgs github:NixOS/nixpkgs/nixos-21.11
$ nix registry pin github:NixOS/nixpkgs/nixos-21.11
$ nix registry list
user github:NixOS/nixpkgs/nixos-21.05 github:NixOS/nixpkgs/1e5c35dfbc8e0ad8c35aa1a6446f442ca1ec5234
user flake:nixpkgs github:NixOS/nixpkgs/nixos-21.11
user github:NixOS/nixpkgs/nixos-21.11 github:NixOS/nixpkgs/068984c00e0d4e54b6684d98f6ac47c92dcb642e
...
global flake:nixpkgs github:NixOS/nixpkgs
...
$ nix eval nixpkgs#lib.version
"21.11pre-git"
(Note that this won’t actually work until the nixos-21.11
branch has been created.)