nix icon indicating copy to clipboard operation
nix copied to clipboard

`nix profile remove --all` keep nix itself by default

Open trim21 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Currently, nix profile remove --all will also remove nix itself, proposal to keep it by default, and require some extra flag or nix profile remove nix to remove it.

(I'm not using NixOS, but nixpkgs on debian, not sure how nix profile remove behave in NixOS.)

ref: https://github.com/NixOS/nix/issues/7966

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Priorities

Add :+1: to issues you find important.

trim21 avatar Oct 18 '24 12:10 trim21

Interesting one. I see a few solutions:

  • Skip Nix when using --all and warn that Nix hasn't been removed
  • Warn that Nix has been removed with instructions on how to reinstall it again using the store path of Nix.
  • Fail the operation altogether to avoid any removal and show error that Nix were to be removed with instructions on how to remove the other entries.

Detection of the Nix profile entry could be the current executable that is part of one of the store paths of a profile entry.

bobvanderlinden avatar Oct 19 '24 08:10 bobvanderlinden

Fail the operation altogether to avoid any removal and show error that Nix were to be removed with instructions on how to remove the other entries.

Sounds like this will make nix profile remove --all unusable at all?

trim21 avatar Oct 19 '24 23:10 trim21

Are you running nix profile as root, or do you have a single user Nix installation? Because, I seem to have this distinction between the 2 profiles. The root one contains nix and nss-cacert, but the "user" one only has my installed packages.

$ nix profile install --profile ./bla nixpkgs#hello
$ ls
bla  bla-1-link
$ nix profile list --profile ./bla
Name:               hello
Flake attribute:    legacyPackages.aarch64-darwin.hello
Original flake URL: flake:nixpkgs
Locked flake URL:   github:nixos/nixpkgs/a9b86fc2290b69375c5542b622088eb6eca2a7c3?narHash=sha256-QUvb6epgKi9pCu9CttRQW4y5NqJ%2BsnKr1FZpG/x3Wtc%3D
Store paths:        /nix/store/0bc59ipsx1x8s9n2nc5h96cd4yhhrh28-hello-2.12.1
$ nix profile remove --profile ./bla --all
removing 'flake:nixpkgs#legacyPackages.aarch64-darwin.hello'
$ sudo nix profile list
warning: $HOME ('/Users/bryanhonof') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
Name:               nix
Store paths:        /nix/store/d88r5b1qv1fvz2j9qndz8sr31mqgz45x-nix-2.24.6

Name:               nss-cacert
Store paths:        /nix/store/9x1bbfhmnsycfq8p5y790jylnjiv0yif-nss-cacert-3.101

In the above example, running nix profile remove --all did not seem to impact the root profile.

bryanhonof avatar Oct 21 '24 12:10 bryanhonof

Are you running nix profile as root, or do you have a single user Nix installation? Because, I seem to have this distinction between the 2 profiles. The root one contains nix and nss-cacert, but the "user" one only has my installed packages.

single user Nix installation, nix is included in nix profile list, and my sudo doesn't have nix command.

In the above example, running nix profile remove --all did not seem to impact the root profile.

Yes, but it get removed from current user's profile

trim21 avatar Oct 22 '24 01:10 trim21

Okay, makes sense. Maybe we could check if argv[0] == thingTryingToRemoveFromProfile because that'd make little sense to remove from a profile.

bryanhonof avatar Oct 22 '24 15:10 bryanhonof