Skip to content

macOS updates often break nix installation (updates replace path-hooks on multi-user install) #3616

Open

Description

@amckinlay

I have noticed that every once and a while /Users/andrewmckinlay/.nix-profile/bin and /nix/var/nix/profiles/default/bin disappear from my $PATH. The last time this happened, the hook nix installed was missing from /etc/zshrc.

Copying the following hook (copied from /etc/bashrc) to /etc/zshrc and restarting the shell fixed everything again:

# 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

My concern is that macOS updates will periodically overwrite /etc/.zshrc (and /etc/.bashrc), requiring effort on my part to reinstall nix. For example, one macOS update overwrote the entire file to fix this misspelling:

andrewmckinlay@imac ~ % diff /etc/zshrc.backup-before-nix /etc/zshrc
3c3
< # Setup user specific overrides for this in ~/.zhsrc. See zshbuiltins(1)
---
> # Setup user specific overrides for this in ~/.zshrc. See zshbuiltins(1)

Both files are read-only anyway, should they really be written to by the nix installer?

Activity

  1. changed the title [-]macOS updates often break nix installation (multi-user install)[/-] [+]macOS updates often break nix installation (updates replace path-hooks on multi-user install)[/+] on May 24, 2020
  2. lilyball commented on Jul 16, 2020

    @lilyball
    Member

    If they keep updating these files, perhaps we should file an Apple Feedback report asking them to add /etc/bashrc.d/ and /etc/zshrc.d folders whose contents get sourced by the default scripts? This way we can add configuration there that won't get overridden.

    Beyond that, the only automatic solution that comes to mind would be to have nix-daemon check these files on launch and re-add the Nix block if it's missing.

  3. ptitvert commented on Jul 23, 2020

    @ptitvert

    I have done a few days before the upgrade to Catalina 10.15.6... and today I wanted to install something to discover that my nix installation was gone!
    Well after some research, I found that the /nix was still there, but everything else was gone... no nix-env command nothing!
    So after cursing a lot... I search until I found this thread...
    I would like also that this problem to solved... For the moment, I have put on my 2 users the following lines in the ~/.profile

    # 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
    

    So I don't care if the /etc/zshrc is or not overwritten in the future... I agree this is a bad solution, but at least for the time being my workaround...

  4. lilyball commented on Jul 27, 2020

    @lilyball
    Member

    I filed feedback for Apple (FB8181728). In the meantime, nix-daemon will need to learn how to modify the files appropriately on launch.

  5. abathur commented on Oct 11, 2020

    @abathur
    Member

    The zsh case seems to have been fixed (but not released yet) in the course of #3456. I haven't observed this same issue with bash shell files.

    Edit: this had its own problems and was reverted.

  6. nixos-discourse commented on Feb 3, 2021

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/here-are-the-etc-bashrc-amendments-performed-by-the-installer-on-macos/11360/1

  7. stale commented on Aug 2, 2021

    @stale

    I marked this as stale due to inactivity. → More info

  8. elliot-u410 commented on Aug 23, 2021

    @elliot-u410

    I'm still seeing this issue as of Nix 2.3.15 and Big Sur 11.5.2. The workaround is to re-add the following to /etc/zshrc:

    # Nix
    if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
      source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
    fi
    # End Nix
  9. abathur commented on Aug 23, 2021

    @abathur
    Member

    I'm still seeing this issue as of Nix 2.3.15 and Big Sur 11.5.2.

    Edit: I see in matrix that #3608 caused its own problems documented in #4169, so I guess a release would actually be a step in the wrong direction atm... Striking through the parts that may not actually be much help...

    FWIW this is roughly expected:

    I would try manually migrating. I think you'd just need to create /etc/zshenv if it doesn't exist, move your source line there, and verify it works.

    Also: brownie points if you (or maybe any zsh user who hasn't taken 11.5.2 yet?) remember to report back here or in #3608 if this migration helps you dodge this problem.

  10. ggPeti commented on Aug 23, 2021

    @ggPeti
    Member

    can't we just patch zsh to use different rcfile paths? users can then set the patched zsh as their shell with nix-darwin

  11. abathur commented on Aug 23, 2021

    @abathur
    Member

    @ggPeti I assume it's ideal if it still works without Nix-darwin, but tbh I have no clue how big the set of (Nix + zsh - nix-darwin) uses is.

    #4169 seems to have a more robust discussion on ~zsh-specific fixes, and I'm trying to fish around for someone to add it to the 2.4 milestone; if I find someone, that might be a good place to pull on the thread...

  12. 63 remaining items

  13. amckinlay commented on Jan 12, 2025

    @amckinlay
    Author

    Please deprecate nix on macOS until this issue is fixed.

  14. ajmas commented on Jan 17, 2025

    @ajmas

    Please deprecate nix on macOS until this issue is fixed.

    You are free to not use it for your own needs, but given there is a workaround, I'd disagree with your suggestion. It would be more constructive to investigate and suggest ways we could resolve this to the benefit of the community as a whole. Additionally this only impacts upgrade time and not general runtime.

  15. michaelfortunato commented on Mar 13, 2025

    @michaelfortunato

    Just got this issue upgrading to 15.3

  16. stavalfi commented on Mar 21, 2025

    @stavalfi

    I'm having hard time making my r&d adopt nix on macOS due to this issue. They all stop use nix and go to homebrew installations after every macOS update.

    Any help?

  17. yanns commented on Mar 21, 2025

    @yanns

    Since I'm using

    [[ ! $(command -v nix) && -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]] && source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
    

    in programs.zsh.initExtra (with homemanager), I've never had any issues anymore.

  18. alper commented on Mar 21, 2025

    @alper

    They all stop use nix and go to homebrew installations after every macOS update.

    I don't think there's that much to be done about that. The convenience differential is enormous even leaving out the breakage during upgrades.

  19. vasigorc commented on Apr 4, 2025

    @vasigorc

    Thank you very much @elliot-u410 and @amckinlay I've already went through a re-install on Mac this year, and just hit nix-shell:63: command not found: nix-shell again after updating to Sequoia 15.4. With this hook everything works as expected!

  20. FranklinYu commented on Apr 9, 2025

    @FranklinYu

    Until we have a solution that survives macOS updates, I suggest removing the part of updating /etc/zshrc (and the Bash counterpart?) from the macOS installer. Reasons:

    1. For new users, this misleads them instead of helping them. They would think that the commands are available because it works when they try the examples immediately after installation. After a while they would notice that they somehow lose access to those commands, and will get very confused what have broken it.
    2. For experienced users, like people above commenting how they “fixed” their own problem, they don’t need this (patching /etc/zshrc) anyway. So this isn’t helping them, either.

    Instead of patching /etc/zshrc, if we simply tell users to source that script from their shell config (like ~/.zshrc or ~/.bashrc), it is only a very little friction (if any at all) for new users. Advantage of this approach:

    1. This is strictly better than the current situation: some users benefit, while others are not hurt.
    2. This doesn’t rule out further improvement in future (such as the one mentioned in macOS updates often break nix installation (updates replace path-hooks on multi-user install) #3616 (comment)). We can get to “the correct solution” later.
    3. This seems relatively easy to implement, and easy to review once implemented.

    Thoughts?

  21. ajmas commented on Apr 16, 2025

    @ajmas

    I recently moved to using Determinate for my Nix Shell, based on a friend's recommendation (he spends more time with system administration than I do).

    I'll need to see how well this survives system updates, so I can't say at this point whether it is a "better" approach. I also haven't investigated the installation to see what it may do differently.

  22. waszkiewiczj commented on Apr 18, 2025

    @waszkiewiczj

    Since I'm using

    [[ ! $(command -v nix) && -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]] && source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
    

    in programs.zsh.initExtra (with homemanager), I've never had any issues anymore.

    I can confirm that the solution works - my Macbook just got a system update and nix works after that. Although I've used programs.zsh.initExtraFirst to make sure that this will always be on top of .zshrc file.

  23. megmug commented on Nov 4, 2025

    @megmug

    I just upgraded from MacOS 26 to 26.1 and it broke the Nix install (official nixos.org installer).
    I can confirm that just re-installing is a workaround, but the installer fails if Nix is already installed because it wants to back up /etc/bashrcand /etc/bash.bashrc, and can't safely do so because it doesn't want to overwrite the old backup that the previous installer created.
    Moving these files around manually enables the installer to go through without further problems.
    All in all, a workaround exists, but it's kind of a cumbersome solution, and it would be great if something could be done to make the experience more user-friendly.

  24. CielSoleil commented on Mar 8, 2026

    @CielSoleil

    Happened to me today. Updating from 26.3 to 26.3.1 Official nix installer. Commands are gone, files are not. However, the bashrc file has the lines nix installer added, zshrc not.

  25. Kiiyya commented on Apr 19, 2026

    @Kiiyya

    Happened to me as well. I am not running nix-darwin, and only run home-manager. I see that for nix-darwin, this is fixed by DeterminateSystems/nix-installer#672.

  26. Abdillah commented on Apr 19, 2026

    @Abdillah

    Nice info @Kiiyya, assuming no bug, then we can install Nix through https://github.com/NixOS/nix-installer/. That PR has been merged here too.

    Just a note, it is different from current official script in the web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmacosNix on macOS, aka OS X, aka darwin

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址