I do this for all the flake inputs my system consumes, as so:
nix = {
# …
registry = lib.mapAttrs (_: value: { flake = value; }) inputs;
nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry;
};
which means I get system registry entries pinned to the revisions used to build /run/current-system
, for e.g.:
system flake:agenix path:/nix/store/pib5m63qfz2plbxz85hk55lv7lfkpzcw-source?lastModified=1695384796&narHash=sha256-TYlE4B0ktPtlJJF9IFxTWrEeq%2BXKG8Ny0gc2FGEAdj0%3D&rev=1f677b3e161d3bdbfd08a939e8f25de2568e0ef4
system flake:home-manager path:/nix/store/35p7gkzlws9xag3szqzgs44jmsp95jp8-source?lastModified=1696371324&narHash=sha256-0ycIheYRxzPOL9XBWiAm/af9cqRmsiy701OpjsRsKiw%3D&rev=e63c30fe9792b57dea1eab98be6871a0e42a33c9
system flake:nixpkgs path:/nix/store/5rb11cz8xmv8cdk7b0w80pzczbzk0p26-source?lastModified=1696193975&narHash=sha256-mnQjUcYgp9Guu3RNVAB2Srr1TqKcPpRXmJf4LJk6KRY%3D&rev=fdd898f8f79e8d2f99ed2ab6b3751811ef683242
…
This works well for me because I update the system regularly, and so it mostly just avoids the unnecessary downloads for the odd ad-hoc nix shell nixpkgs#…
in between. Putting them in nixPath also means the same thing for most of the legacy commands that would otherwise fail to import <nixpkgs>
because I don’t have channels defined at all any more.
But as noted, it doesn’t affect the revisions in any of my development workspaces’ flake.lock
. Nor should it; that should be isolated from the surrounding system environment. Typically, I get the same devshell environment I was using when I last worked on the project in question, and the first thing I do is update to current.
What I haven’t looked into, but might be useful, is to work out a way for nix flake update
in that workspace to update to the revision in the system registry, rather than the absolute most recent version. In my case, that’s commonly close enough to current that it doesn’t matter, although it’s usually a different revision, because I typically have systems tracking nixos-unstable
and development flakes tracking nixpkgs-unstable
. But sometimes around a major bulk rebuild, I can wind up with these minor differences resulting in a bunch of extra unexpected downloads.