So after years without a problem, I’ve finally hit a “macOS upgrade breaks my nix” problem, with Sonoma 14.6.1 on apple silicon, but it doesn’t seem to fit a pattern I’ve found by searching.
The problem is that the two /Library/LaunchDaemons/org.nixos.* services seem to be forgotten by launchd somehow after a reboot. The files are still correctly there, but after a reboot, launchctl print system/org.nixos.darwin-store (or system/org.nixos.nix-daemon) fails with:
Bad request.
Could not find service "org.nixos.darwin-store" in domain for system
and sudo launchctl kickstart -k system/org.nixos.darwin-store fails with Could not find service "org.nixos.darwin-store" in domain for system (same for nix-daemon).
If I manually run this after reboot, everything fully works:
sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.darwin-store.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl kickstart -k system/org.nixos.darwin-store
sudo launchctl kickstart -k system/org.nixos.nix-daemon
but then the next reboot still fails.
Does anyone have any tips for getting the launchctl bootstrap to persist, like it has done for every previous version of macOS on this machine?
What do you see with launchctl print-disabled system? Any chance org.nixos.nix-daemon is in that list? I would have expected that bootstrapping a disabled service would re-enable it (or alternatively would tell you it’s disabled), but I haven’t done any testing around that.
If the service is disabled, you can use launchctl enable system/org.nixos.nix-daemon. Heck, try running that even if it’s not showing up as disabled.
And this doesn’t change with the two launchctl enable commands. But the services do not appear in launchctl list after a reboot. In fact, if I just sudo launchctl load the two /Library/LaunchDaemons paths after a reboot, then everything is working again just from that.
Any further ideas? Thanks for the suggestions so far!
Note that launchctl list shows your user services, you need sudo launchctl list to show system services, which is why launchctl print system is the preferred command.
Assuming launchctl print system after reboot continues to not show them, my next suggestion is to check the permissions on the files. ls -l /Library/LaunchDaemons/org.nixos*. They must be owned by root, and must not allow group or world writes.
So I’ve fixed it, but the change in behavior from previous versions is a little weird.
I did a launchctl print for everything in /Library/LaunchDaemons, and noticed there were a bunch that were unknown after a reboot. Moreover, they missing services seemed to be correlated with disabled items under System Settings > Login Items > Allow in the Background.
There were two “Allow in the Background” items listed only as “sh” and “from an unidentified developer” that I had disabled ages ago, based on not knowing what they were:
It turns out these correspond to the two nix services, and re-enabling them solved the problem. I had no idea these were system LaunchDaemons, rather than something under ~/Library. For previous versions of macOS, this apparently had no effect, but in 14.6.1, they do.