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

ZSH config sometimes needs to be added to user instead of global on MacOS #558

Open
BagMan9 opened this issue Jul 7, 2023 · 11 comments
Open
Labels
MacOS Darwin/MacOS

Comments

@BagMan9
Copy link

BagMan9 commented Jul 7, 2023

Error

Error: 
   0: Install failure
   1: Self test
   2: Shell `zsh` failed self-test with command `"zsh" "-ic" "nix build --no-link --expr \'derivation { name = \"self-test-zsh-1688696922719\"; system = \"aarch64-darwin\"; builder = \"/bin/sh\"; args = [\"-c\" \"echo hello > \\$out\"]; }\'"`, stderr:
   2: zsh:1: command not found: nix

Metadata

key value
version 0.10.0
os macos
arch aarch64

Initially, I thought the issue was not adding nix to my .zshrc, but even after adding nix, sourcing it, and a reboot, it doesn't seem to be working.

This is what I added for reference:

# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
    . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix

I am running macOS Sonoma, which is beta software. If this is expected, or you guys don't want to deal with issues on beta hardware, I totally understand.

@Hoverbear
Copy link
Contributor

Hoverbear commented Jul 7, 2023

After chatting with @cole-h I think we should only be warning for these errors.

Could you help me fully understand the situation?

  • Can you run nix from your normal shell?
  • Can you run sh then run nix in it?
  • Can you verify your $PATH contains a nix related path? /nix/...

@BagMan9
Copy link
Author

BagMan9 commented Jul 7, 2023

Sorry, meant to put that in after the zshrc code block:

  • Nix cannot be run from my normal shell (zsh)
  • Nix is not in my path and does not get placed there automatically. I manually added it to my path (seperate from that code block) it still does not work
  • I did not check to see if sh worked, I will check that now

I went ahead and nuked my install completely and am starting from scratch. I'll see if maybe there was something small I missed.

@BagMan9
Copy link
Author

BagMan9 commented Jul 7, 2023

Re ran it again and manually added nix to the path worked this time:

# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
    . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix
path+=("/nix/var/nix/profiles/default/bin/")

However, this did not get added by the install script, and I don't have a particularly weird dotfile setup, so it seems odd that it didn't get added (or perhaps this is expected behavior?)

@Hoverbear
Copy link
Contributor

Which file did you add this code to?

@BagMan9
Copy link
Author

BagMan9 commented Jul 8, 2023

~/.zshrc

@Hoverbear
Copy link
Contributor

The self-test uses root's zsh, I wonder if your root's zsh somehow isn't importing the system zsh profiles...

@BagMan9
Copy link
Author

BagMan9 commented Jul 10, 2023

I sudo su'd into my root profile, there is no .zshrc present in root's home dir. /etc/zshrc does contain the Nix if statement (#Nix-#End Nix), but no path appends or prepends.

@Hoverbear Hoverbear added the MacOS Darwin/MacOS label Jul 14, 2023
@Hoverbear
Copy link
Contributor

Does Nix work from your root zsh shell? The . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh line should be the one that does most of the work.

@BagMan9
Copy link
Author

BagMan9 commented Jul 15, 2023

Yes, it does work from my root zsh shell.

@Hoverbear Hoverbear changed the title Self-test fails on macOS Self-test fails on macOS (but shell works) Jul 17, 2023
@CalebBurton
Copy link

CalebBurton commented Aug 12, 2023

I ran into this same issue this week on both a 2022 M1 macbook running macOS 13.5 and a 2015 Intel macbook running macOS 12.6.8. In both cases the installer gives the same warning that BagMan9 posted in the issue description. From the comments, I tried switching around to different shells with the following results:

My normal shell (zsh):

> which nix
nix not found

Switching into sh:

> sh
> which nix
(blank)

Switching into root (zsh):

> sudo su -
> which nix
/var/root/.nix-profile/bin/nix

EDIT: I ran into similar problems with the official installer. This comment helped me get things working: not only do you have to add the daemon script to your local zshrc, you also have to remove it from the global zshrc.

@Hoverbear
Copy link
Contributor

Self testing is no longer a failure, but a warning.

However this issue is still open since it's also describing a Mac issue with zsh.

@Hoverbear Hoverbear changed the title Self-test fails on macOS (but shell works) ZSH config sometimes needs to be added to user instead of global on MacOS Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MacOS Darwin/MacOS
Projects
None yet
Development

No branches or pull requests

3 participants