How to nix profile upgrade nix

For the case where flakes are enabled via ~/.config/nix/nix.conf:

experimental-features = nix-command flakes

How does one upgrade the nix version?

nix profile upgrade nix

does not do anything.

Also:

  • Is it possible to install a specific nix version?
  • Can the nix version impact the outcome of a build (i.e. the hash of built binary)?

you may first need a nix profile install nix

version: nix profile install github:NixOS/nix/2.6.0#

impact: no, the version should not impact the path of the build. A different outcome of the build binary is more likely due to a non-reproducible build. (normal Nix builds are addressed by the hash of their inputs and build instructions - the derivation - not the output contents)

1 Like

Thanks!

I get the following:

$ nix profile install nix
error: packages '/nix/store/fxygga1i4s95xrpq943qdbqpk3qwy79z-nix-2.8.0pre20220307_92b8d4d/libexec/nix/build-remote' and '/nix/store/6wljmq98mf555cqqahjryjbkpsg6jlx3-nix-2.7pre20220124_0a70b37/libexec/nix/build-remote' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' to change the priority of one of the conflicting packages (0 being the highest priority)

In order to try flakes, I initially followed Practical Nix Flakes

nix-env -f '<nixpkgs>' -iA nixUnstable
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.c

I’m wondering if there is a conflict between the legacy and new ways …?

Yeah, you already have one installed, so another on top is a conflict. If all you want is to try things out this is the easiest for what you have now:

nix shell nix

Installing via nix profile will change your ~/.nix-profile. If you end up with a problem just delete it and re-make a symlink to your old profile via something like ln -snf /nix/var/nix/profiles/per-user/$HOME/profile $HOME/.nix-profile

If you don’t care about your old nix-env profiles, just delete the ~/.nix-profile symlinks and run nix profile install nix. Alternatively you can install to a different profile nix profile install nix --profile ./some-path

1 Like

Ok thanks! At the moment I feel I’m in for the long run with flakes, so I’d rather have a long term installation approach. :slight_smile:

Not sure I fully understand. Deleting the file (symlink) ($HOME/.nix-profile) renders the nix profile command non-operational:

$ nix profile install nix
-bash: /home/sylvain/.nix-profile/bin/nix: No such file or directory

From following the symlinks, the ~/.nix-profile links to

$ ls -l .nix-profile 
.nix-profile -> /nix/var/nix/profiles/per-user/sylvain/profile
$ ls -l /nix/var/nix/profiles/per-user/sylvain/profile
/nix/var/nix/profiles/per-user/sylvain/profile -> profile-7-link
$ ls -l /nix/var/nix/profiles/per-user/sylvain/profile-7-link
/nix/var/nix/profiles/per-user/sylvain/profile-7-link -> /nix/store/9sjphl1izy2f9xw2ksz0ndh63fqdhvl6-profile

It seems that whatever I delete I won’t have the bin/nix command available, as I currently only have one profile.

$ ls -l /nix/var/nix/profiles/per-user/sylvain/profile*
/nix/var/nix/profiles/per-user/sylvain/profile -> profile-7-link
/nix/var/nix/profiles/per-user/sylvain/profile-7-link -> /nix/store/9sjphl1izy2f9xw2ksz0ndh63fqdhvl6-profile

So, I installed to a different profile as you suggested:

$ nix profile --profile ~/.nix-profile2 install nix

Deleted ~/.nix-profile, and copied ~/.nix-profile2 into default profile location (~/.nix-profile):

cp -r ~/.nix-profile2 ~/.nix-profile

There’s probably a simpler way to do this … and I’m not sure this approach actually works, as when I run nix profile upgrade nix I get:

$ nix profile upgrade nix
warning: 'nix' does not match any packages
warning: Use 'nix profile list' to see the current profile.
$ nix profile list
0 flake:nix#defaultPackage.x86_64-linux github:NixOS/nix/92b8d4d8861b908a7ec500526a84155c597d6d2b#defaultPackage.x86_64-linux /nix/store/fxygga1i4s95xrpq943qdbqpk3qwy79z-nix-2.8.0pre20220307_92b8d4d

My original profile, with the nix that I cannot figure out how to upgrade:

$ nix profile list
0 - - /nix/store/j3z4bd88qk6ln7ykikxa1bb612pjjvkx-cachix-0.7.0
1 - - /nix/store/6wljmq98mf555cqqahjryjbkpsg6jlx3-nix-2.7pre20220124_0a70b37
2 - - /nix/store/m2hr19fnix4qsd14j3wdw9kijz3x2l72-rust_carnix-0.10.0
3 - - /nix/store/xn2vp71in8fpnz0viqs66s0lqdvcp7vi-niv-0.2.19-bin
4 - - /nix/store/8n83ig414sxywz9qqc53d15ww7g08c3l-python3.9-nix-prefetch-github-5.0.1
5 github:kamadorueda/alejandra/0.7.0#defaultPackage.x86_64-linux github:kamadorueda/alejandra/a618751be3605f08e5bd2ddde6ee06a0b0d8723c#defaultPackage.x86_64-linux /nix/store/qrhvl59ap9v5sv70hhppb355b04qbviw-alejandra-0.7.0+20220228.a618751

Removed nix with:

$ nix profile remove nix

Re-installed, using the explicit path to nix, since it is no longer symlinked, e.g.:

$ /nix/var/nix/profiles/per-user/sylvain/profile-7-link/bin/nix profile install nix

Now:


$ nix profile list
0 - - /nix/store/j3z4bd88qk6ln7ykikxa1bb612pjjvkx-cachix-0.7.0
1 - - /nix/store/m2hr19fnix4qsd14j3wdw9kijz3x2l72-rust_carnix-0.10.0
2 - - /nix/store/xn2vp71in8fpnz0viqs66s0lqdvcp7vi-niv-0.2.19-bin
3 - - /nix/store/8n83ig414sxywz9qqc53d15ww7g08c3l-python3.9-nix-prefetch-github-5.0.1
4 github:kamadorueda/alejandra/0.7.0#defaultPackage.x86_64-linux github:kamadorueda/alejandra/a618751be3605f08e5bd2ddde6ee06a0b0d8723c#defaultPackage.x86_64-linux /nix/store/qrhvl59ap9v5sv70hhppb355b04qbviw-alejandra-0.7.0+20220228.a618751
5 flake:nix#defaultPackage.x86_64-linux github:NixOS/nix/92b8d4d8861b908a7ec500526a84155c597d6d2b#defaultPackage.x86_64-linux /nix/store/fxygga1i4s95xrpq943qdbqpk3qwy79z-nix-2.8.0pre20220307_92b8d4d

Still not sure how to upgrade :slight_smile: though:

$ nix profile upgrade 5
error: opening directory '/nix/store/azanfdwpnpwsq2iwdzjf9zkb5b9fqqb1-nix-2.8.0pre20220307_92b8d4d-doc': No such file or directory
1 Like

Solves the original issue of no --priority flag being there

Hosted by Flying Circus.