nix icon indicating copy to clipboard operation
nix copied to clipboard

`nix upgrade-nix` is broken

Open smaret opened this issue 3 years ago • 14 comments

Describe the bug

It seems that nix upgrade-nix is incompatible with nix profile.

Steps To Reproduce

  1. Install a package with nix profile install nixpkgs#hello
  2. 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

smaret avatar Nov 03 '21 10:11 smaret

I am stuck with the same problem. Is there any workaround?

kamoii avatar Jan 21 '22 10:01 kamoii

@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 avatar Jan 24 '22 09:01 smaret

@smaret Thanks for your reply. Unfortunately, I think I installed nix through install script. I tried upgrade just to be sure, but nothing happened.

kamoii avatar Jan 24 '22 19:01 kamoii

Same here, installed with nix install script so nix profile can't update it, stuck with a nix that can't be updated :/

Litarvan avatar Mar 04 '22 01:03 Litarvan

If you have installed nix with nix profile install [...]

@smaret the thing is you can't do that due to #6373

develop7 avatar Apr 25 '22 05:04 develop7

Are there any workarounds to this problem?

derekmahar avatar May 19 '22 19:05 derekmahar

@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

develop7 avatar May 19 '22 23:05 develop7

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 avatar May 28 '22 13:05 lkupcsik

@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:

m0ar avatar Aug 26 '22 10:08 m0ar

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

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

derekmahar avatar Nov 09 '22 18:11 derekmahar

I'm surprised I had to do this still in 2023.

kevinfiol avatar Sep 07 '23 15:09 kevinfiol

I wrote a script which fully automates the steps in your workaround:

what about nss-cacert? is it upgradable the same way?

ink-splatters avatar Apr 19 '24 07:04 ink-splatters

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

nixos-discourse avatar Apr 19 '24 07:04 nixos-discourse

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.

截屏2024-05-23 17 46 46

towry avatar May 23 '24 09:05 towry

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

xsteadfastx avatar Aug 08 '24 09:08 xsteadfastx