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

Is nix-darwin installing a second Nix? #931

Open
lucianthorr opened this issue Apr 13, 2024 · 29 comments
Open

Is nix-darwin installing a second Nix? #931

lucianthorr opened this issue Apr 13, 2024 · 29 comments

Comments

@lucianthorr
Copy link

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

@thuvasooriya
Copy link

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?

@Samasaur1
Copy link
Contributor

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>

@thuvasooriya
Copy link

thuvasooriya commented Apr 24, 2024

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

@Samasaur1
Copy link
Contributor

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

@thuvasooriya
Copy link

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

@Samasaur1
Copy link
Contributor

@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

@lucianthorr
Copy link
Author

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?

@bestlem
Copy link

bestlem commented Apr 24, 2024

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

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

@Samasaur1
Copy link
Contributor

@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
Copy link
Contributor

Samasaur1 commented Apr 24, 2024

@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
Copy link
Contributor

@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

@thuvasooriya
Copy link

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

@bestlem
Copy link

bestlem commented Apr 25, 2024

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

@remi-gelinas
Copy link

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

@bestlem
Copy link

bestlem commented May 2, 2024

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

@gshpychka
Copy link
Contributor

How do you do step 3 - Uninstall standalone Nix.

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

@Samasaur1
Copy link
Contributor

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

@jeeftor
Copy link

jeeftor commented May 15, 2024

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)

@afh
Copy link

afh commented May 15, 2024

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.

@bestlem
Copy link

bestlem commented May 15, 2024

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

@afh
Copy link

afh commented May 15, 2024

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.

@Samasaur1
Copy link
Contributor

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
Copy link
Contributor

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?

@afh
Copy link

afh commented May 16, 2024

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?

@Samasaur1
Copy link
Contributor

Samasaur1 commented May 16, 2024

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"

@afh
Copy link

afh commented May 16, 2024

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

@jeeftor
Copy link

jeeftor commented May 16, 2024

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

@Samasaur1
Copy link
Contributor

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
Copy link
Contributor

Samasaur1 commented May 16, 2024

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

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

No branches or pull requests

8 participants