By default nixpkgs#hello
will pull the nix unstable. But we can lock it on the command line by using nixpkgs/release-23.11#hello
. This is fine but its too verbose. I can add a flake registry to lock nixpkgs like this:
nix registry add nixpkgs github:NixOS/nixpkgs/release-23.11
Now nixpkgs#hello
should be following the release-23.11
The question is, what if I already have this in my store (for example by using home-manager). Currently I have this setting which ensures <nixpkgs>
is the same pkgs version I have in home manager (within nix conf)
nix-path = nixpkgs=${pkgs.path}
I wish to do the same with flakes, but if I add this:
nix.registry = {
nixpkgs.to = {
type = "path";
path = "${pkgs.path}";
};
};
Then each time I run nix shell nixpkgs#hello
it tries to copy pkgs.path
to the store even though its already in store. I there any way to set the registry to a path and not have it copied each time (when its already in store). Alternatively are there further docs to describe all types of registry as I couldn’t find much in man pages. Currently the only option seems to be setting it to github and fix to a branch/rev
I had this for NixOS but after seeing your post I noticed that I didn’t set the nix-path for home-manager only installs. Something like this should work for hm:
nix.registry = {
# Make nix command use the same nixpkgs version: 'nix shell nixpkgs#curl'
nixpkgs.flake = inputs.nixpkgs;
nixpkgs-unstable.flake = inputs.nixpkgs-unstable; # 'nix shell nixpkgs-unstable#curl'
};
nix.package = pkgs.nix;
nix.settings = {
experimental-features = "nix-command flakes";
nix-path = ["nixpkgs=${inputs.nixpkgs.outPath}" "nixpkgs-unstable=${inputs.nixpkgs.outPath}"];
};
1 Like
Thanks this is exactly what I was looking for. btw I don’t use NixOS, but this worked like a charm on home manager non nixos too, note that I had to pass nixpkgs
to home.nix as you pointed out and not use pkgs.path
extraSpecialArgs = {
inherit nixpkgs;
};
This resulted in the following registry
{
"exact": true,
"from": {
"id": "nixpkgs",
"type": "indirect"
},
"to": {
"lastModified": 1701282334,
"narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=",
"path": "/nix/store/j8han9cf3g8vba52yhiklaa6a500pcbv-source",
"rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e",
"type": "path"
}
}
Main difference being that it has a narHash
. So if using path
flakes already in store, must provide a narHash
with exact = true