nix
                                
                                 nix copied to clipboard
                                
                                    nix copied to clipboard
                            
                            
                            
                        `nix upgrade-nix` is broken
Describe the bug
It seems that nix upgrade-nix is incompatible with nix profile.
Steps To Reproduce
- Install a package with nix profile install nixpkgs#hello
- Try to upgrade nix with nix upgrade-nix. The following error is displayed:
nix upgrade-nix 
error: directory '/Users/smaret/.nix-profile/bin' does not appear to be part of a Nix profile
Expected behavior
nix upgrade-nix  should upgrade to the latest stable release
nix-env --version output
nix-env --version
nix-env (Nix) 2.4
Additional information
Relevant line in nix source code: https://github.com/NixOS/nix/blob/7c90552879da4d1df99b50c85e94201981e60123/src/nix/upgrade-nix.cc#L122
I am stuck with the same problem. Is there any workaround?
@kamoii If you have installed nix with nix profile install  [...], you should be able to upgrade it with nix profile upgrade NUMBER, where NUMBER is the number corresponding to nix in your nix profile (you can get it with nix profile list).
@smaret Thanks for your reply. Unfortunately, I think I installed nix through install script. I tried upgrade just to be sure, but nothing happened.
Same here, installed with nix install script so nix profile can't update it, stuck with a nix that can't be updated :/
If you have installed nix with
nix profile install [...]
@smaret the thing is you can't do that due to #6373
Are there any workarounds to this problem?
@derekmahar essentially it's nix profile install nixpkgs#nix then nix profile remove <whatever number old nix is listed under in nix profile list output>. you might not be able to actually link new nix to the profile because of the binaries conflict but you're still able to reach new nix directly by /nix/store/gjr9ylm023rl9di484g1wxcd1jp84xxv-nix-2.8.1/bin/nix.
after that nix  profile upgrade legacyPackages.x86_64-linux.nix should do the job
hope that helps
disclaimer: all the above works for me in single-user nix installation in openSUSE Tumbleweed, not NixOS
Workaround:
ls -l `which nix`
, then record the path to the nix executable
nix profile list, then check which number is your nix installation.
nix profile remove [number] (removes the symlink, but the executable is still in nix store)
/nix/store/.../bin/nix profile install nixpkgs#nix (using the path recorded above)
nix --version
nix (Nix) 2.8.1
@lkupcsik When I try this I get an error:
error: opening directory '/nix/store/50h63qd56mij2jx2h2bzi6cw531s8cxa-nix-2.10.3-debug': No such file or directory
Any idea how to continue?
EDIT:
After running /nix/store/.../bin/nix store repair /nix/store/.../nix-2.10.3-debug , and continuing this chain for the next similar issues with -dev and -doc, it finally succeeds :+1:
Workaround:
ls -l `which nix`, then record the path to the nix executable
nix profile list, then check which number is your nix installation.nix profile remove [number](removes the symlink, but the executable is still in nix store)
/nix/store/.../bin/nix profile install nixpkgs#nix(using the path recorded above)
nix --versionnix (Nix) 2.8.1
I wrote a script which fully automates the steps in your workaround:
# Record path to nix executable.
nix_binary_path=$(readlink -f $(which nix))
# Record index of nix installation in profile.
nix_profile_index=$(nix profile list | grep $(echo $nix_binary_path | sed 's|^/nix/store/\([^/]*\)/.*$|\1|g') | cut -d ' ' -f 1)
# Remove the symbolic link to the nix executable.
nix profile remove $nix_profile_index
# Install the latest nix release.
$nix_binary_path profile install nixpkgs#nix
# Display the new nix version.
nix --version
I'm surprised I had to do this still in 2023.
I wrote a script which fully automates the steps in your workaround:
what about nss-cacert? is it upgradable the same way?
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/nix-upgrade-nix-fails-with-mysterious-error/26875/2
I don't know why, but i do some upgrade by following the doc here https://nixos.org/manual/nix/stable/installation/upgrading
my nix version goes from 2.22.x to 2.18.2, then i run nix upgrade-nix, my nix version goes from 2.18.2 to 2.18.1.
i also struggle with this. before i had version nix (Nix) 2.24.0pre20240717_464e5925. after running the workaround im back on 2.18.5. what is going on? also nix upgrade-nix is still throwing this error:
error: directory '/home/marv/.nix-profile/bin' does not appear to be part of a Nix profile
and its broken complete:
nix profile list
error: profile manifest '/nix/var/nix/profiles/per-user/marv/profile/manifest.json' has unsupported version 3
thanks lord for nix profile rollback.  one thing i discovered... ~/.nix-profile is no symlink. even if it has the exact content of /nix/var/...
~ on  main
❯ exa --git -la /nix/var/nix/profiles/per-user/marv/profile
dr-xr-xr-x   - marv  1 Jan  1970 bin
dr-xr-xr-x   - marv  1 Jan  1970 etc
lrwxrwxrwx   - marv  1 Jan  1970 include -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/include
dr-xr-xr-x   - marv  1 Jan  1970 lib
dr-xr-xr-x   - marv  1 Jan  1970 libexec
.r--r--r-- 281 marv  1 Jan  1970 manifest.json
lrwxrwxrwx   - marv  1 Jan  1970 opt -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/opt
lrwxrwxrwx   - marv  1 Jan  1970 sbin -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/sbin
dr-xr-xr-x   - marv  1 Jan  1970 share
~ on  main
❯ exa --git -la .nix-profile/
dr-xr-xr-x   - marv  1 Jan  1970 bin
dr-xr-xr-x   - marv  1 Jan  1970 etc
lrwxrwxrwx   - marv  1 Jan  1970 include -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/include
dr-xr-xr-x   - marv  1 Jan  1970 lib
dr-xr-xr-x   - marv  1 Jan  1970 libexec
.r--r--r-- 281 marv  1 Jan  1970 manifest.json
lrwxrwxrwx   - marv  1 Jan  1970 opt -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/opt
lrwxrwxrwx   - marv  1 Jan  1970 sbin -> /nix/store/z51if3zpdi8szimjay9ii9qiq4bflgxb-home-manager-path/sbin
dr-xr-xr-x   - marv  1 Jan  1970 share