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

Nix daemon fails to start on macOS 10.15 Catalina #3125

Closed
callahad opened this issue Oct 8, 2019 · 11 comments
Closed

Nix daemon fails to start on macOS 10.15 Catalina #3125

callahad opened this issue Oct 8, 2019 · 11 comments

Comments

@callahad
Copy link
Member

callahad commented Oct 8, 2019

Describe the bug
The Nix daemon does not start after boot for multi-user installations on macOS 10.15 (Catalina).

To Reproduce

  1. Prepare macOS 10.15 (Catalina) for Nix:

    1. echo 'nix' | sudo tee -a /etc/synthetic.conf

    2. Reboot

    3. Create the Nix volume:

      sudo diskutil apfs addVolume disk1 APFSX Nix -mountpoint /nix
      sudo diskutil enableOwnership /nix
      sudo chflags hidden /nix
      echo "LABEL=Nix /nix apfs rw" | sudo tee -a /etc/fstab
      
  2. Install Nix with sh <(curl https://nixos.org/nix/install) --daemon

  3. Reboot

Observed behavior

Nix stops working after reboot; commands fail with:

error: cannot connect to daemon at `/nix/var/nix/daemon-socket/socket': Connection refused

Similarly, the Nix daemon is not seen by launchd: launchctl list | grep nix finds nothing.

Root Cause

Nix installs /Library/LaunchDaemons/org.nixos.nix-daemon.plist as a symlink into the Nix store.

At boot, launchd sees this as a dangling symlink as the Nix volume is not mounted early enough. Thus, it is unable to load the plist, and the nix daemon does not start.

Workaround

You can manually start the daemon after each boot with launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist && launchctl start org.nixos.nix-daemon.

Alternatively, manually copy the plist into /Library/LaunchDaemons, replacing the symlink with an actual copy of the file.

If you do the latter, you may want to adjust the paths inside the plist to point to /nix/var/nix/profiles/default/bin/nix-daemon rather than a specific derivation inside the Nix store.

Metadata

  • system: "x86_64-darwin"
  • host os: Darwin 19.0.0, macOS 10.15
  • multi-user?: yes
  • sandbox: no
  • version: nix-env (Nix) 2.3
  • channels(root): "nixpkgs-20.03pre194957.bef773ed53f"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixpkgs
@mroi
Copy link

mroi commented Oct 8, 2019

Isn’t this issue supposed to be fixed by 800fba1?

@callahad
Copy link
Member Author

callahad commented Oct 8, 2019

That commit is a necessary but incomplete fix.

It only ensures that org.nixos.nix-daemon.plist waits until /nix is mounted before it tries to run nix-daemon.

But if launchd can't read org.nixos.nix-daemon.plist, then it fails immediately and nothing we put inside that file matters.

This fails because the multi-user installer symlinks the plist, and that symlink is broken if /nix isn't mounted. Apparently /nix is not yet mounted when launchd attempts to read that file at boot.

@mroi
Copy link

mroi commented Oct 8, 2019

Damn. Thanks for clearing this up.

@ElvishJerricco
Copy link
Contributor

How reasonable would it be to just copy the plist instead of symlinking it?

@matthewbauer
Copy link
Member

matthewbauer commented Oct 9, 2019

Yeah missed this one. Copying the file would be necessary unfortunately. The reason we do the symlink is to get updates automatically for Nix. Migration step would be:

sudo cp -f `readlink /Library/LaunchDaemons/org.nixos.nix-daemon.plist` /Library/LaunchDaemons/org.nixos.nix-daemon.plist

matthewbauer added a commit to matthewbauer/nix that referenced this issue Oct 9, 2019
On Catalina, the /nix filesystem might not be mounted at start time.
To avoid this service not starting, we need to keep the launch agent
outside of the Nix store. A wait4pid will hold for our /nix dir to be
mounted.

Fixes NixOS#3125.
@matthewbauer
Copy link
Member

Opened #3128

edolstra pushed a commit that referenced this issue Jan 4, 2020
On Catalina, the /nix filesystem might not be mounted at start time.
To avoid this service not starting, we need to keep the launch agent
outside of the Nix store. A wait4pid will hold for our /nix dir to be
mounted.

Fixes #3125.

(cherry picked from commit 0847f2f)
@arnalyse
Copy link

Although this issue is closed, I wanted to mention that the installation fails with the copy command, in case the target file exists. I got the following error:

---- sudo execution ------------------------------------------------------------
I am executing:

    $ sudo cp -f /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist /Library/LaunchDaemons/org.nixos.nix-daemon.plist

to set up the nix-daemon as a LaunchDaemon

cp: /Library/LaunchDaemons/org.nixos.nix-daemon.plist and /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist are identical (not copied).

Maybe it would be safer to remove the file and then do the copy.

@matthewbauer
Copy link
Member

Although this issue is closed, I wanted to mention that the installation fails with the copy command, in case the target file exists. I got the following error:

---- sudo execution ------------------------------------------------------------
I am executing:

    $ sudo cp -f /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist /Library/LaunchDaemons/org.nixos.nix-daemon.plist

to set up the nix-daemon as a LaunchDaemon

cp: /Library/LaunchDaemons/org.nixos.nix-daemon.plist and /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist are identical (not copied).

Maybe it would be safer to remove the file and then do the copy.

Is that a fatal error? If so, that sounds like the sane thing to do.

@domenkozar
Copy link
Member

i also hit this, but I don't think it should be fatal. It's a leftover from previous installation and can be just copied over.

@domenkozar
Copy link
Member

It would be better to use install ...

@domenkozar
Copy link
Member

#3532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants