nix icon indicating copy to clipboard operation
nix copied to clipboard

nix profile upgrade: allow upgrading by derivation name when it is unambiguous.

Open lolbinarycat opened this issue 10 months ago • 1 comments

Is your feature request related to a problem? Please describe. upgrading a single package that was installed as the default package from a flake is cumbersome, only being possible by specifying an index

Describe the solution you'd like allow the user to specify the name of an installed derivation instead of a regex, index number, or attribute path.

if there is exactly one installed store path whose name portion (with version removed) matches that name, that package is upgraded.

if there is any other number of matches, an error is thrown.

Describe alternatives you've considered

  1. lock this behavior behind a --name flag
  2. allow regex matching on store paths

Additional context nix-env often encountered issues when using derivation names, however, there are a few factors that make this different:

  1. nix-env searched all of nixpkgs, not just the packages that were installed, leading to horrible performance
  2. nix-env required names to not change in updates, this would only use the names to select which package is updated, not to actually perform the update

Priorities

Add :+1: to issues you find important.

lolbinarycat avatar Apr 05 '24 21:04 lolbinarycat

Indices don't exist in the current version of nix anymore, but I agree that this is currently quite annoying.

Name:               path:/Users/feuh/.dotfiles#packages.aarch64-darwin.default
Flake attribute:    packages.aarch64-darwin.default
Original flake URL: path:/Users/feuh/.dotfiles
Locked flake URL:   path:/Users/feuh/.dotfiles?lastModified=1713790916&narHash=sha256-C70FD1A3HN9GYxX68wouOvnFrChxtucNoy84P3eICJs%3D
Store paths:        /nix/store/v5xqrwf9jcadgc2z4nr9fmp8qjbi2p2d-ifreilicht-default-packages

A potential solution could also be to improve the logic that generates the human-readable name to use the derivation's name if the package is the default output. In that case, the above entry from nix profile list would read:

Name:               ifreilicht-default-packages
Flake attribute:    packages.aarch64-darwin.default
Original flake URL: path:/Users/feuh/.dotfiles
Locked flake URL:   path:/Users/feuh/.dotfiles?lastModified=1713790916&narHash=sha256-C70FD1A3HN9GYxX68wouOvnFrChxtucNoy84P3eICJs%3D
Store paths:        /nix/store/v5xqrwf9jcadgc2z4nr9fmp8qjbi2p2d-ifreilicht-default-packages

iFreilicht avatar May 03 '24 07:05 iFreilicht

@iFreilicht I think the reason your example does not work is because the repository/directory is called .dotfiles. This is currently not being matched. I'm not entirely sure whether we should want to implicitly make the human url name .dotfiles.

You can see that most file: urls should be working fine:

https://github.com/NixOS/nix/blob/16232497458ceac64b00ff81033a22b739331f91/tests/unit/libexpr/flake/url-name.cc#L9-L17

I do agree that --name would be nice to have for these off-cases though. This was also part of the original proposal, but it hasn't been implemented yet.

That said, is the goal of this issue to have --name? From the description it sounds like a duplicate from https://github.com/NixOS/nix/issues/7967. Maybe a new issue for --name specifically is in order.

bobvanderlinden avatar May 13 '24 18:05 bobvanderlinden