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 upgrade-nix is broken #5473

Open
smaret opened this issue Nov 3, 2021 · 15 comments
Open

nix upgrade-nix is broken #5473

smaret opened this issue Nov 3, 2021 · 15 comments
Labels

Comments

@smaret
Copy link
Member

smaret commented Nov 3, 2021

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:

if (baseNameOf(where) != "bin" ||

@smaret smaret added the bug label Nov 3, 2021
@kamoii
Copy link

kamoii commented Jan 21, 2022

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

@smaret
Copy link
Member Author

smaret commented Jan 24, 2022

@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).

@kamoii
Copy link

kamoii commented Jan 24, 2022

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

@Litarvan
Copy link

Litarvan commented Mar 4, 2022

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

@develop7
Copy link

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

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

@derekmahar
Copy link

Are there any workarounds to this problem?

@develop7
Copy link

@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

@lkupcsik
Copy link

lkupcsik commented May 28, 2022

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

@m0ar
Copy link

m0ar commented Aug 26, 2022

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

@derekmahar
Copy link

derekmahar commented Nov 9, 2022

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

@kevinfiol
Copy link

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

achuie added a commit to achuie/dotfiles that referenced this issue Oct 7, 2023
9999years added a commit to 9999years/topgrade that referenced this issue Nov 27, 2023
Also check that Nix can be upgraded before running `nix upgrade-nix` to
work around a bug.

See: <NixOS/nix#5473>
SteveLauC pushed a commit to topgrade-rs/topgrade that referenced this issue Dec 21, 2023
Make `nix upgrade-nix` a separate step

Also check that Nix can be upgraded before running `nix upgrade-nix` to
work around a bug.

See: <NixOS/nix#5473>
kachick added a commit to kachick/dotfiles that referenced this issue Mar 12, 2024
NixOS/nix#5473

I dont have confidence this way is...
@ink-splatters
Copy link

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

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

@nixos-discourse
Copy link

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

@towry
Copy link

towry commented May 23, 2024

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

@xsteadfastx
Copy link

xsteadfastx commented Aug 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests