Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix profile subcommands rely on index identifier #7961

Closed
bobvanderlinden opened this issue Mar 4, 2023 · 2 comments
Closed

nix profile subcommands rely on index identifier #7961

bobvanderlinden opened this issue Mar 4, 2023 · 2 comments
Labels
bug new-cli Relating to the "nix" command

Comments

@bobvanderlinden
Copy link
Member

The main identifier for package entries in Nix profiles is the index. The index is quite bad as an identifier. Consider the following scenario:

$ nix profile list
....
3 flake:nixpkgs#legacyPackages.x86_64-linux.vim github:NixOS/nixpkgs/9952d6bc395f5841262b006fbace8dd7e143b634#legacyPackages.x86_64-linux.vim /nix/store/9hcby08vmd6k3zl3clwvlw5y5vkmc3z6-vim-9.0.0609
4 flake:nixpkgs#legacyPackages.x86_64-linux.cowsay github:NixOS/nixpkgs/9952d6bc395f5841262b006fbace8dd7e143b634#legacyPackages.x86_64-linux.cowsay /nix/store/azn0g0m6yg6m9vmdp3wq6wjbsd1znv44-cowsay-3.7.0 /nix/store/qgsl9bd6vvnpjaxhdnzg0xmycg3652c0-cowsay-3.7.0-man
5 flake:nixpkgs#legacyPackages.x86_64-linux.nano github:NixOS/nixpkgs/9952d6bc395f5841262b006fbace8dd7e143b634#legacyPackages.x86_64-linux.nano /nix/store/hhr8ijr2p5qf3lyklzyw8cndhsmpklsv-nano-7.2
$ nix profile remove 3
removing 'flake:nixpkgs#legacyPackages.x86_64-linux.vim'
$ nix profile remove 4
removing 'flake:nixpkgs#legacyPackages.x86_64-linux.nano'

In this case the numeric identifier in nix profile shifts with every change of the profile. In this case the user intended to remove vim and cowsay, but instead removed vim and nano. Very confusing.

The identifier in nix profile should be stable. It is probably up for debate what that should be.

@roberth roberth added the new-cli Relating to the "nix" command label Mar 16, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/flakes-as-a-unified-format-for-profiles/29476/1

@bobvanderlinden
Copy link
Member Author

bobvanderlinden commented Dec 21, 2023

This has been partly fixed by #8678. The commands now use a name which is inferred from installables (flake uris). This makes this issue significantly less problematic, but it still can occur.

Installing 2 different packages using 2 different flake uris that infer to the same name will cause the problem to occur.

For example installing github:NixOS/nixpkgs#cowsay and github:NixOS/nixpkgs/nixpkgs-unstable#cowsay will result in cowsay and cowsay-2 entries in nix profile. Removing cowsay will implicitly rename cowsay-2 to cowsay.

To make this stable, it shouldn't be possible to install 2 installables that infer to the same name. Or the names should be stored, so that entries do not appear to implicitly rename.

The first option seems most reliable and intuitive, so solving #5587 will solve this issue as well. I'll close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new-cli Relating to the "nix" command
Projects
None yet
Development

No branches or pull requests

3 participants