nix icon indicating copy to clipboard operation
nix copied to clipboard

Nix daemon crash on macOS 26 Beta

Open andre4ik3 opened this issue 7 months ago • 13 comments

Describe the bug

When trying to install/run packages on macOS 26 Developer Beta 1, Nix exits with a "daemon disconnected unexpectedly" error:

Image

Screenshot

Steps To Reproduce

  1. Install macOS 26 Developer Beta 1
  2. Install Nix (using either official or Determinate Nix installer; both succeed but Nix fails so I'm assuming it's an error with Nix)
  3. Try to run e.g. nix run nixpkgs#hello or nix shell nixpkgs#hello
  4. Observe error: "Nix daemon disconnected unexpectedly (maybe it crashed?)"

Expected behavior

nix run nixpkgs#hello produces "Hello, world!"

Metadata

nix-env (Nix) 2.29.0

Additional context

In /var/log/nix-daemon.log, there is the following error:

accepted connection from pid 8877, user andre4ik3
objc[8879]: +[NSCharacterSet initialize] may have been in progress in another thread when fork() was called.
objc[8879]: +[NSCharacterSet initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

Checklist


Add :+1: to issues you find important.

andre4ik3 avatar Jun 10 '25 10:06 andre4ik3

This issue can be reproduced with the official Nix installer, the Determinate installer when installing upstream Nix, and the Lix installer.

But Determinate Nix works fine:

Image

See also: https://github.com/DeterminateSystems/determinate/issues/100

andre4ik3 avatar Jun 10 '25 13:06 andre4ik3

Having this issue too. Got this error after DFU restore on a Mac Mini 2024, and upgrading to 26 Tahoe.

invranet avatar Jun 10 '25 15:06 invranet

When upgrading to macos 26 beta and having nix installed it works. But Reinstalling it I am not too sure if that causes an issue?

Image

nix-info:

 - system: `"aarch64-darwin"`
 - host os: `Darwin 25.0.0, macOS 16.0`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.28.3`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/store/zxdp3r7mnikb6mjs8d8fl92d25j6p6c4-source`

Specs:

- model: `Macbook Pro`
- chip: `M4`
- Ram: `16gb`
- Storage: `1tb`

Eveeifyeve avatar Jun 10 '25 20:06 Eveeifyeve

I haven't tested upgrading yet as I don't want to risk my main machine having issues. All of the errors described above were encountered on a M1 MacBook Pro or virtual machines that were both directly wiped and reset to the new beta IPSW file. They were not upgraded from any prior macOS version and they did not have Nix installed on them previously.

andre4ik3 avatar Jun 10 '25 21:06 andre4ik3

When upgrading to macos 26 beta and having nix installed it works. But Reinstalling it I am not too sure if that causes an issue?

On my MacBook Pro 2024 M4 it does work. This seems to be only an issue after a fresh install of Nix on macOS 26 most likely.

Just in-case of a case of confusion

I have:

  • Mac Mini 2024 M4 - Affected machine after a DFU mode restore.
  • MacBook Pro 2024 M4 - Not affected, Nix installed on macOS Sequoia, upgraded to 26 Tahoe... still functions.

invranet avatar Jun 10 '25 21:06 invranet

Having the same issue after updating my mac to macOS 26.

Im not a nix expert, but i've been trough a lot of debugging by now and it seems to be related to the substituters.

This worked for me: nix develop --option substituters "https://cache.nixos.org"

With direnv: use flake --option substituters "https://cache.nixos.org"

konkonam avatar Jun 11 '25 18:06 konkonam

This worked for me: nix develop --option substituters "https://cache.nixos.org"

Doesn't work for me. And also https://cache.nixos.org is the default substituter, so I don't see how that option would change anything (unless you had extra custom substituters defined?)

Image

Image

But again this is a clean, non-upgraded macOS 26 install. Maybe it is different when upgrading from previous macOS. I haven't tested upgrading yet but I'll try installing a macOS 15 VM, then installing Nix, then upgrading it to 26.

andre4ik3 avatar Jun 12 '25 09:06 andre4ik3

Okay, I tested upgrading. Here is a Nix installation in a macOS Sequoia VM:

Successful Nix install on Sequoia

And here it is upon upgrading:

Broken install on Tahoe

So, it appears that any store paths already saved locally will continue to work. It's only working after upgrading because the store paths you are testing are saved locally. Removing those paths, or evaluating any new ones, will cause the daemon crash.

More precisely, since the daemon log explicitly calls out fork(), I believe that any operation that causes the Nix daemon to fork will crash it.

andre4ik3 avatar Jun 13 '25 04:06 andre4ik3

this sounds suspiciously similar to the general macos fork safety problem. might be worth trying to set OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES set in your daemon in /Library/LaunchDaemons/org.nixos.nix-daemon.plist, though ideally that shouldn't be needed. it looks like OBJC_DISABLE_INITIALIZE_FORK_SAFETY was removed from org.nixos.nix-daemon.plist in 8105307f0f3caeae1c1d0bca51bee3a417e4304a. for what it's worth i set up a vm via tart and it seems to be working okay despite OBJC_DISABLE_INITIALIZE_FORK_SAFETY not being set.

$ tart clone ghcr.io/cirruslabs/macos-tahoe-vanilla:latest tahoe-vanilla
$ tart run tahoe-vanilla

$ curl -L https://github.com/DeterminateSystems/nix-installer/releases/download/v3.6.2/nix-installer-aarch64-linux -o nix-installer
$ chmod +x nix-installer
$ NIX_INSTALLER_DETERMINATE=false ./nix-installer install --no-confirm
$ nix run nixpkgs#hello
Hello, world!

joshheinrichs-shopify avatar Jun 15 '25 00:06 joshheinrichs-shopify

I can confirm that it works on Darwin 26 after setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES in daemon

szpolny avatar Jun 16 '25 11:06 szpolny

I can also confirm that it works on Darwin 26 after setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES in the daemon environment.

invranet avatar Jun 17 '25 08:06 invranet

Can also confirm it works on all affected systems (both clean installs and after upgrading) after setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES:

Image

To script this workaround, e.g. for automation:

sudo plutil -insert EnvironmentVariables -dictionary /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo plutil -insert EnvironmentVariables.OBJC_DISABLE_INITIALIZE_FORK_SAFETY -string YES /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist

andre4ik3 avatar Jun 17 '25 09:06 andre4ik3

To script this workaround, e.g. for automation:

sudo plutil -insert EnvironmentVariables -dictionary /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo plutil -insert EnvironmentVariables.OBJC_DISABLE_INITIALIZE_FORK_SAFETY -string YES /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist

Haha didn't know much about how I was going to do that, lol. I'm going to add that soon to my script, cheers for that!

invranet avatar Jun 17 '25 11:06 invranet

Thank you @andre4ik3 for the solution! I can confirm it works on Tahoe Beta 2.

Image

szympajka avatar Jul 05 '25 16:07 szympajka

Can anyone confirm whether this is still needed on macOS 26 release?

dhess avatar Sep 16 '25 10:09 dhess

Can anyone confirm whether this is still needed on macOS 26 release?

It is not needed anymore. Just installed nix through the determinate installer with curl -fsSL https://install.determinate.systems/nix | sh -s -- install on a new 26.0 macOS system and it works flawlessly.

gador avatar Sep 17 '25 19:09 gador

Can also confirm that it works fine, using the official installer (not the Determinate one). No workaround needed anymore, so maybe it was a macOS bug in the beta. As such I'm closing the issue now.

Nix working with official installer on macOS Tahoe final release

andre4ik3 avatar Sep 18 '25 01:09 andre4ik3