Nix: Install on Mac Os with zsh fails to update .zshrc file

Created on 23 Sep 2017  Â·  15Comments  Â·  Source: NixOS/nix

Installing nix on mac os using

$ curl https://nixos.org/nix/install | sh

is not updating the .zshrc file with

# 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

preventing zsh from finding the nix commands.

installer question

Most helpful comment

I'm seeing this in general just not work, even when manually running that command:

➜  ~ nix-shell
zsh: command not found: nix-shell
➜  ~ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
➜  ~ nix-shell
zsh: command not found: nix-shell

Running the same thing from bash works

➜  ~ bash
bash-3.2$ nix-shell
bash: nix-shell: command not found
bash-3.2$ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
bash-3.2$ nix-shell

[nix-shell:~]$ 

Still have the underlying issue of /etc/zshrc vs. updating ~/.zshrc.

System: macOS High Sierra 10.13.1 Beta (17B25c)
Nix version: 1.11.15
Nixpkgs version: 18.03pre116432.263185aa68
Sandboxing enabled: false

All 15 comments

i can confirm this, i've evaluated a fresh install on a private machine yesterday

I'm seeing this in general just not work, even when manually running that command:

➜  ~ nix-shell
zsh: command not found: nix-shell
➜  ~ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
➜  ~ nix-shell
zsh: command not found: nix-shell

Running the same thing from bash works

➜  ~ bash
bash-3.2$ nix-shell
bash: nix-shell: command not found
bash-3.2$ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
bash-3.2$ nix-shell

[nix-shell:~]$ 

Still have the underlying issue of /etc/zshrc vs. updating ~/.zshrc.

System: macOS High Sierra 10.13.1 Beta (17B25c)
Nix version: 1.11.15
Nixpkgs version: 18.03pre116432.263185aa68
Sandboxing enabled: false

Thanks for checking. Just to add details, I think that adding that line manually to my ~/.zshrc and sourcing .zshrc I could run at least nix-env -i. I'm pretty sure I tested the git installation and worked. I'll verify it later, I don't have my laptop at the moment.

cc @grahamc who probably knows the installer code the most nowadays

I verified and I confirm that both nix-env --version and nix-shell --version work after adding the nix-daemon launch to the ~/.zshrc manually

Interesting! This is pretty unfortunate, as I don't have a mac to test with other than the one running H.S. and that has other problems :/ The installer _shouldn't_ write to ~/.zshrc, but instead;

readonly PROFILE_TARGETS=("/etc/profile" "/etc/bashrc" "/etc/zshrc")

Do you have an /etc/zshrc? What about an /etc/zprofile? Re-reading the man-page for zsh, I now realize I misread this line:

Login shells source /etc/profile followed by $HOME/.profile.

as it only does that in _compatibility mode_.

--

A fix here is to ensure /etc/zshrc or /etc/zprofile are created if they don't exist, if your shell is zsh.

I have both /etc/zshrc and /etc/zprofile. The nix installer only updated zshrc.

FWIW, doing some debugging utilizing echo $__ETC_PROFILE_NIX_SOURCED to figure out if the . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' has been run (same system stuff as above, but now on beta 2, macOS High Sierra 10.13.1 Beta (17B35a)):

  1. Base case: no changes to /etc/zshrc (nix-daemon.sh there) and /etc/zprofile (nix-daemon.sh not there)

    • echo $__ETC_PROFILE_NIX_SOURCED returns 1, but nix-shell command not found

    • subsequent recalls to . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' are noop b/c it's already sourced

  2. Flip: /etc/zshrc (nix-daemon.sh not there) and /etc/zprofile (nix-daemon.sh there)

    • echo $__ETC_PROFILE_NIX_SOURCED returns 1, but nix-shell command not found

    • subsequent recalls to . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' are noop b/c it's already sourced

  3. Remove both : /etc/zshrc (nix-daemon.sh not there) and /etc/zprofile (nix-daemon.sh not there)

    • echo $__ETC_PROFILE_NIX_SOURCED returns nothing (nix-shell command not found)

    • Then call . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh', which since not already sourced, does something

    • nix-shell now works from zsh

  4. Remove both & update ~/.zshrc : /etc/zshrc (nix-daemon.sh not there) and /etc/zprofile (nix-daemon.sh not there); ~/.zshrc now has the call

    • echo $__ETC_PROFILE_NIX_SOURCED returns 1, AND nix-shell command found

Haven't gone back to documentation to explain what's going on, but for now, just using the work around from step 4.

adding that line (in the OP description) to the end of my .zshrc file fixed up the problem it would seem.

Adding the line . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh to the end of ~/.zshrc didn't fixed it for me. I'm using MacOS High Sierra. Have tried quitting and restarting terminal.

I'm facing the same issue

I also have this issue. Removing the nix lines from /etc/zshrc and adding

# 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

in ~/.zshrc fixed the issue for me.

I fixed it by source the shell file that is mentioned at the end of successful nix installation. On my mac it is:
. $HOME/.nix-profile/etc/profile.d/nix.sh
And it worked.

This may have already been fixed since it's gone nearly 2 years without a comment? In any case, a number of the underlying details have changed.

Does not appear fixed. Had the exact same problem just now and needed the same fix.

I faced the same issues and the workaround mentioned fixed my issue.

Was this page helpful?
0 / 5 - 0 ratings