nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

Is nix-darwin installing a second Nix?

Open lucianthorr opened this issue 4 months ago • 29 comments

I'm following the instructions here and it seems like I now have two versions of Nix installed. Determinate Systems currently installed 2.20.5 Then after running nix run nix-darwin -- switch --flake ~/.config/nix-darwin, my nix --version is 2.18.2. nix-doctor also states that I have two conflicting nixes.

Is that to be expected?
It's confusing (as a total newbie) also because I'm not sure what my PATH should be set to in .zshenv

export PATH="/nix/var/nix/profiles/default/bin:$PATH" <-- Determinate export PATH="/run/current-system/sw/bin:$PATH" <--nix-darwin

lucianthorr avatar Apr 13 '24 12:04 lucianthorr

Yeah I also have this issue, I found this when I was trying to update the nix version.

My nix doctor output:

[FAIL] Multiple versions of nix found in PATH:
  /nix/store/4xwvps7bnachw9686ac22jhczn04i44b-nix-2.20.5/bin
  /nix/store/8wj64myqgglm4pi59qs1w18ky9qqii6f-nix-2.18.2/bin


error: not an absolute path: '~/Library'

Is this expected of nix-darwin?

thuvasooriya avatar Apr 16 '24 17:04 thuvasooriya

What probably happened is that you installed Nix itself, and then nix-darwin installed its own version of Nix. You can list your imperatively installed packages with nix-env --query and nix profile list. For packages that show up in nix-env --query, you can uninstall them with nix-env --uninstall <pkg>; for packages that show up in nix profile list, you can uninstall them with nix profile uninstall <pkg>

Samasaur1 avatar Apr 24 '24 04:04 Samasaur1

What probably happened is that you installed Nix itself, and then nix-darwin installed its own version of Nix.

@Samasaur1 But According to the instructions we can use the nix-installer from the determinate systems to install nix before installing nix-darwin right? Then how come this behavior of two nix installations is expected.

We can't technically install nix-darwin without having nix so what would be a proper method of installation for flake nix-darwin

thuvasooriya avatar Apr 24 '24 17:04 thuvasooriya

I think this is just a situation where there's no better way to do it

Samasaur1 avatar Apr 24 '24 18:04 Samasaur1

@Samasaur1 forgive me if I'm dumb but does this mean every single nix-darwin installation have such a problem of two nix installations?

thuvasooriya avatar Apr 24 '24 18:04 thuvasooriya

@thuvasooriya You'll have two Nix installations at some point. As far as I can tell, the best thing to do is

  1. Install Nix
  2. Install nix-darwin (which comes with its own version of Nix)
  3. Uninstall standalone Nix

I kind of hate this, but I don't see a better way to do it. You need Nix to install nix-darwin, and nix-darwin should manage the systemwide version of Nix. And it just seems like a really bad idea to have the nix-darwin installer try to uninstall standalone Nix unprompted

Samasaur1 avatar Apr 24 '24 18:04 Samasaur1

What kind of management does the nix-darwin do to the systemwide nix? Is there a way the darwin features could be inside the systemwide nix rather than wrapping it?

lucianthorr avatar Apr 24 '24 18:04 lucianthorr

@Samasaur1 How do you do step 3 - Uninstall standalone Nix.

Also how do you upgrade nix (nix upgrade-nix does not work)

bestlem avatar Apr 24 '24 20:04 bestlem

@lucianthorr When I say nix-darwin "manages" the systemwide Nix, I mean that the Nix first on your PATH should come from nix-darwin. This means it's declaratively configured, pinned to a reproducible version, and all the other benefits that you get from installing software with nix-darwin over imperatively installing software. This is all-around a good thing, it just so happens that you need Nix to install nix-darwin in the first place.

Samasaur1 avatar Apr 24 '24 21:04 Samasaur1

@bestlem see below

What probably happened is that you installed Nix itself, and then nix-darwin installed its own version of Nix. You can list your imperatively installed packages with nix-env --query and nix profile list. For packages that show up in nix-env --query, you can uninstall them with nix-env --uninstall <pkg>; for packages that show up in nix profile list, you can uninstall them with nix profile uninstall <pkg>

I don't have anything installed imperatively anymore, but if you post the output of both nix-env --query and nix profile list on your system, I can help you figure out exactly how to uninstall the second version of Nix

Samasaur1 avatar Apr 24 '24 21:04 Samasaur1

@bestlem oh also I forgot to answer your other question. Nix-Darwin defaults to the latest stable Nix, and you probably don't want to override this to a newer version. If you do, though, there's the nix.package option

Samasaur1 avatar Apr 25 '24 00:04 Samasaur1

@Samasaur1 Thanks for the reply. I kind of get the chicken and the egg problem here but I guess the nix-installer from the declarative systems is made in such a way to not allow nix uninstallation without removing nix-darwin first which would break a hell lot of stuff afaik. Check this out And I'm not sure how to safely uninstall that nix and figure out which one is from nix-darwin and which one is the one I installed. update: I just checked the above comments but maybe there is something wrong with my nix installation but I didn't have any output for nix-env --query and nix profile list

I think the readme file should be updated with regards to these issues and possible headaches associated with it. I would be willing to make a pull request with updated instructions because afaik uninstalling nix-darwin installed via flakes also require different commands from the ones that've been mentioned in the readme file.

I guess an optional safe script to install nix and install nix-darwin and then uninstall the imperatively installed nix is a good choice to have since I haven't seem much devs playing with two nix versions at the same system. I'm just a beginner getting started with nix and I might be wrong. Please correct me.

thuvasooriya avatar Apr 25 '24 03:04 thuvasooriya

@bestlem see below

What probably happened is that you installed Nix itself, and then nix-darwin installed its own version of Nix. You can list your imperatively installed packages with nix-env --query and nix profile list. For packages that show up in nix-env --query, you can uninstall them with nix-env --uninstall <pkg>; for packages that show up in nix profile list, you can uninstall them with nix profile uninstall <pkg>

I don't have anything installed imperatively anymore, but if you post the output of both nix-env --query and nix profile list on your system, I can help you figure out exactly how to uninstall the second version of Nix

I am using flakes only. Sometimes doing a darwin-rebuild others just home-manager - from the same flake. If done using darwin-rebuild both those commands give no result, if via home-manager (nix build build .#"homeConfigurations.{user}@{machine}.activationPackage) they show home-manager-path

The two nixes are one from Nix-Darwin and the other from the installer (in my case determinate systems) Originally they were version 2.18.x and 2.20.x but somehow my Nix-Darwin version is now 2.21.2 and so I don't need the installer version.

bestlem avatar Apr 25 '24 12:04 bestlem

I have this same issue, but for some reason the default profile is taking precedence over the systemwide Nix package in my path - so I always end up only referencing the Determinate Systems-installed Nix version, which is older than I want to run :/

remi-gelinas avatar May 01 '24 22:05 remi-gelinas

@remi-gelinas Which shell are you using? and what is your $PATH

bestlem avatar May 02 '24 04:05 bestlem

How do you do step 3 - Uninstall standalone Nix.

sudo -i nix-env --uninstall nix worked for me.

gshpychka avatar May 14 '24 11:05 gshpychka

You can't uninstall the Determine Systems-installed Nix while using nix-darwin. However, it doesn't really cause issues (the nix-darwin nix is used instead), so I'd just leave it as is

Samasaur1 avatar May 15 '24 00:05 Samasaur1

I don't know if this is related -> but I'm seeing the same stuff.

Once I install Darwin I can no longer run nix-shell -p xxxx (I assume this is because its a flake install maybe)

jeeftor avatar May 15 '24 14:05 jeeftor

I don't mind having two installations of nix when using nix-darwin, if both versions are somewhat recent. On my system nix-darwin uses 2.18.1, yet the latest version available as of this writing is 2.21.0.

What does it take to update the nix that nix-darwin uses? What are reasons that nix-darwin should stay on older releases?

I'm curious and would appreciated if someone more knowledgable could provide some context on this.

afh avatar May 15 '24 17:05 afh

@afh Upgrade (and downgrade) can be done in your config files by setting option

nix.package = pkgs.nixVersions.latest

or any of the nixVersions you can find in searching nixpkgs

There are some regressions added by later version of nix so if your system is working then I would leave it. I upgraded as later nix do have a debugger rather than just --show-trace and no doubt other improvements.

bestlem avatar May 15 '24 17:05 bestlem

Thank you @bestlem, that's very helpful to know. I hear you lound and clear on leaving it, and I'll probably regret my decision to change the installed nix version, when things break, yet I'm keen on exploring the details of nix and nix-darwin more (including newer language features) and think there is benefit for me.

afh avatar May 15 '24 17:05 afh

You should almost definitely stay on Nix 2.18. Later versions are kind of just bug-filled messes, and so nixpkgs is staying on Nix 2.18 for a reason.

Samasaur1 avatar May 15 '24 21:05 Samasaur1

I don't know if this is related -> but I'm seeing the same stuff.

Once I install Darwin I can no longer run nix-shell -p xxxx (I assume this is because its a flake install maybe)

@jeeftor what do you see when you try that?

Samasaur1 avatar May 15 '24 21:05 Samasaur1

Thank you for chiming in, @Samasaur1. I was under the impression that the older nix was more a nix-darwin thing rather than nixpkgs. Thanks for clearing that up.

From your experience what makes later versions of Nix kind of a bug filled mess?

afh avatar May 16 '24 03:05 afh

From your experience what makes later versions of Nix kind of a bug filled mess?

@afh I actually haven't used Nix > 2.18.x for specifically this reason. That said, I've seen lots of reports of Nix bugs in the Matrix rooms/other places, and they're fairly frequently caused by regressions. You can also look at the issues on NixOS/nix, some of which are labeled with "regression"

Samasaur1 avatar May 16 '24 03:05 Samasaur1

@Samasaur1 on first glance 31 open regressions doesn't look to bad to me, but again I've only scratched Nix's surface, if even, so happy to trust the judgement of folks that are more involved.

Out of curiosity: do you think an update of Nix in nixpkgs and nix-darwin will come with the next release, this year or even further out in the future?

afh avatar May 16 '24 14:05 afh

I don't know if this is related -> but I'm seeing the same stuff. Once I install Darwin I can no longer run nix-shell -p xxxx (I assume this is because its a flake install maybe)

@jeeftor what do you see when you try that?

My issue was related to using determinate and not copying all the paths over... but previously only nix shell nixpkgs#xxx would work - after the fix that and nix-shell -p both work

jeeftor avatar May 16 '24 15:05 jeeftor

I don't know if this is related -> but I'm seeing the same stuff. Once I install Darwin I can no longer run nix-shell -p xxxx (I assume this is because its a flake install maybe)

@jeeftor what do you see when you try that?

My issue was related to using determinate and not copying all the paths over... but previously only nix shell nixpkgs#xxx would work - after the fix that and nix-shell -p both work

Glad you figured it out!

Samasaur1 avatar May 16 '24 19:05 Samasaur1

@afh I don't really keep up with development of Nix the language, so I'm not sure. I do know that there are some alternative implementations that specifically target stability (Lix comes to mind), so you could use those if you wanted.

Samasaur1 avatar May 16 '24 19:05 Samasaur1