-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Is your feature request related to a problem? Please describe.
When using nix profile install, it's annoying to always download the latest version of nixpkgs just to install a single package, especially when using unstable. Luckily, there's a solution; pinning nixpkgs to the current latest revision with nix registry pin nixpkgs. This has the desired effect of preventing re-downloads of nixpkgs.
However, this can be a bit of a foot-gun, as nix profile upgrade effectively becomes a no-op now. Nix will try to fetch the latest version of flake:nixpkgs, sees that this is pinned to a specific revision, reuse that revision, notice that there's no updates and exit. The user will never get a single update if they don't know that they have to run nix registry pin nixpkgs again!
This is similar to existing confusion around users forgetting nix-channel --update before nix-env --upgrade.
Describe the solution you'd like
nix profile upgrade should warn the user if the flake a package comes from is pinned in the registry, and explain that they may want to run nix registry pin <flake> first.
This warning should be given for all pinned flakes that prevent an upgrade when upgrading multiple packages, for example when running nix profile upgrade '.*', but only for those that actually have a new revision available!
Ideally, the advice should only be given once for each flake once, even if multiple packages are held back because of it. The output could look something like this:
$ nix profile upgrade '.*'
warning: flake 'nixpkgs' is pinned to 'github:NixOS/nixpkgs/842e90934a352f517d23963df3ec0474612e483c', preventing vim, python3, asdf-vm, hello, cowsay from being upgraded.
You may want to run
nix registry pin nixpkgs
to pin 'nixpkgs' to the latest version and then run
nix profile upgrade '.*'
once more.
I propose using this multi-line format to ensure a long list of packages doesn't distract from the solution text, and to allow easy copying of the commands and avoid confusion about where the command starts and ends.
We may have to consider that it is theoretically possible to pin flakes in the global registry as well, in which case registry pin would also fail to produce a new version, though I guess that's a potential feature request for nix registry instead.
Describe alternatives you've considered
The additional feature of only showing the warning only for flakes that actually have a newer revision available is not strictly required, but does reduce noise when users upgrade a lot of packages from different flakes at once.
nix profile upgrade could also upgrade the base flake as well, as it is ~somewhat likely that a user actually wants to do that. While it is probably a bad idea to do that by default, an interactive prompt that says: "Do you want to re-pin
The ouput could also be less sophisticated, like
$ nix profile upgrade '.*'
warning: vim will not be upgraded as flake 'nixpkgs' is pinned to 'github:NixOS/nixpkgs/842e90934a352f517d23963df3ec0474612e483c'
warning: python3 will not be upgraded as flake 'nixpkgs' is pinned to 'github:NixOS/nixpkgs/842e90934a352f517d23963df3ec0474612e483c'
warning: hello will not be upgraded as flake 'nixpkgs' is pinned to 'github:NixOS/nixpkgs/842e90934a352f517d23963df3ec0474612e483c'
warning: cowsay will not be upgraded as flake 'nixpkgs' is pinned to 'github:NixOS/nixpkgs/842e90934a352f517d23963df3ec0474612e483c'
This is very noisy though and doesn't help the user much to resolve the problem. And if we have a final message to tell the user what to do, making the warning more concise reduces the mental load required to see the solution text.
Additional context
I just discovered this now while testing for another feature I'm working on. I'm not sure how many people pin their flakes in practice.
Priorities
Add 👍 to issues you find important.