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 2.0 on macOS High Sierra - error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket' #1980

Open
teuffy opened this issue Mar 15, 2018 · 32 comments
Assignees
Labels
installer macos Nix on macOS, aka OS X, aka darwin

Comments

@teuffy
Copy link

teuffy commented Mar 15, 2018

nix-env (Nix) 2.0

-- fresh install on mbp high sierra with
$ bash <(curl https://nixos.org/nix/install)

-- testing with
nix-shell -p nix-info --run "nix-info -m"

-- output
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': No such file or directory
(use '--show-trace' to show detailed location information)

-- with trace
error: while evaluating the attribute '__impureHostDeps' of the derivation 'shell' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating 'unique' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/lists.nix:483:12, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:137:13:
while evaluating 'concatMap' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/lists.nix:102:18, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:137:25:
while evaluating anonymous function at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:137:40, called from undefined position:
while evaluating the attribute 'darwin.CF' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/os-specific/darwin/apple-source-releases/default.nix:199:5:
while evaluating 'callPackageWith' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/customisation.nix:113:35, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/os-specific/darwin/apple-source-releases/default.nix:199:23:
while evaluating 'makeOverridable' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/customisation.nix:72:24, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/customisation.nix:117:8:
while evaluating anonymous function at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix:1:1, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/lib/customisation.nix:74:12:
while evaluating the attribute 'cc.isClang' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/default.nix:137:14:
while evaluating anonymous function at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/darwin/default.nix:82:49:
while evaluating the attribute 'args' of the derivation 'Libsystem-osx-10.11.6' at /nix/store/7c23fi7pyh8gzrg733i6xhijb3344cp4-nixpkgs-18.09pre131986.893b69a54cb/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': No such file or directory

-- with sudo
sudo nix-shell -p nix-info --run "nix-info -m"

error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13

@peti peti added installer macos Nix on macOS, aka OS X, aka darwin labels Mar 16, 2018
@peti
Copy link
Member

peti commented Mar 16, 2018

Did you source the newly installed shell profile script before entering the nix-enx command to make sure that you shell's environment is set up properly?

And if you, then what is the shell environment in which you run the nix-env command exactly?

@teuffy
Copy link
Author

teuffy commented Mar 16, 2018

  • Sourcing do you mean source bashrc or ~/.bash_profile ? I did it, restarted the terminal and even the machine
  • shell environnement - using bash with user profile . I followed the install instruction for bashrc and zshrc. I haven't touch the $NIX_PATH

@peti
Copy link
Member

peti commented Mar 17, 2018

I believe that the system-wide profile is going to source the Nix-specific one automatically once it's installed, i.e. there should be an entry for Nix in /etc/profile.d, if I'm not mistaken.

In any case, what is the shell environment in which you run the nix-env command exactly? The output of env would be helpful.

@LnL7
Copy link
Member

LnL7 commented Mar 17, 2018

I think the daemon isn't running for some reason, what's the output of this command?

sudo launchctl list | grep org.nixos

@teuffy
Copy link
Author

teuffy commented Mar 17, 2018

sudo launchctl list | grep org.nixos

119 0 org.nixos.nix-daemon

@jeffreyrosenbluth
Copy link

I'm having the exact same issue. Running High Sierra 10.13.3 (17D102)

@LnL7
Copy link
Member

LnL7 commented Mar 22, 2018

@teuffy Strange, that indicates the daemon is running. Does restarting it help?

sudo launchctl kickstart -k system/org.nixos.nix-daemon

@Tehnix
Copy link

Tehnix commented Mar 22, 2018

Getting the same error and tried running sudo launchctl kickstart -k system/org.nixos.nix-daemon, but no success :(

EDIT: A full reboot seems to have done the trick though!

@jeffreyrosenbluth
Copy link

Ah, a full reboot worked for me as well.

@LnL7
Copy link
Member

LnL7 commented Mar 24, 2018

That's odd, is 05cb8e5 not in 2.0?

@robsimmons
Copy link

Same here, log-out and log-in to my account did not work, had to reboot the laptop. (macOS 10.12.6)

@shlevy
Copy link
Member

shlevy commented Mar 27, 2018

I think the plist hard-codes the path to the daemon, so you need to launchctl unload then launchctl load it again

@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@gbersac
Copy link

gbersac commented Apr 10, 2018

Same issue for me :

$ nix-shell -p nix-info --run "nix-info -m"
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': No such file or directory

@waylandc
Copy link

@Tehnix

confirmed that a full reboot fixes problem on High Sierra 10.13.4 and nix 2.0.4

@nekoniaow
Copy link

nekoniaow commented Aug 30, 2019

I confirm that I experienced this issue as well and that rebooting is indeed an effective workaround.
This is for macOS Mojave 10.14.6 and nix 2.2.2.

@hlolli
Copy link
Member

hlolli commented Oct 16, 2019

Experiencing this now on Catalina, I am attempting to reinstall /nix, which succeeded after creating /nix.

I didn't get this error (but some SSL error) when trying to install nix-darwin, but after the restart this started to appear

$ nix-shell -p nix-info --run "nix-info -m"
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': Connection refused

the output of launchctl

$ sudo launchctl list | grep org.nixos
Password:
-	126	org.nixos.activate-system

ADDED:
nevermind, all I had to do was sudo chown -R hlolli /nixand the error went away.

@zhengqunkoo
Copy link

zhengqunkoo commented Nov 13, 2019

Different operating system, but logging in again allows connectino to daemon on Linux. Problem was probably due to unset permissions.

@zhujinxuan
Copy link

zhujinxuan commented Dec 9, 2019

Same problem happens in Catalina. But the problem is in the mac's side that the mac mounts / as read only.

Solution for me:

sudo mount -uw /

@domenkozar
Copy link
Member

Seems like on macos the daemon takes some time to reload, so you can see this error for about 10s before it boots up.

@domenkozar
Copy link
Member

$ sudo pkill -HUP nix-daemon
$ nix-build -A git '<nixpkgs>'
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': Connection refused
(use '--show-trace' to show detailed location information)
$ nix-build -A git '<nixpkgs>'
/nix/store/29p4nwvp9dwwk2l8w8d3ciss30hzf0kl-git-2.21.0

@timokau
Copy link
Member

timokau commented Dec 22, 2019

I occasionally get the same error on system rebuilds on nixos:

activating the configuration...
setting up /etc...
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': Connection refused
Activation script snippet 'nix' failed (1)
restarting systemd...

@stale
Copy link

stale bot commented Feb 14, 2021

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

1 similar comment
@stale
Copy link

stale bot commented Aug 13, 2021

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

@Serif-7
Copy link

Serif-7 commented Feb 19, 2023

I am also having this issue on Fedora 37. Reboots have not worked. A reinstall did, for a while, but the issue has popped up again.

@stale stale bot removed the stale label Feb 19, 2023
@alessandrocandolini
Copy link

I'm also getting this issue on mac os every time I try to upgrade the nix installation following the guidelines here https://nixos.org/manual/nix/stable/installation/upgrading.html I always need to re-install nix from scratch, which is quite annoying. Anyone has an idea why this is happening and how to prevent it?

@jonasschultheiss
Copy link

same @alessandrocandolini, thats currently my problem. what do you mean by re-installing from scratch?

@jonasschultheiss
Copy link

ah nevermind, just had to restart my mac

@dbaynard
Copy link

dbaynard commented Nov 5, 2023

I hit the issue on darwin with error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': Connection refused — in my case, because of a broken upgrade. I've been able to fix this (copying a plist file from the nix store to /Library/LaunchDaemons/) but it is then deleted on an upgrade.

Edit: found a fix for the deletion on upgrade, following #6499 (comment) — replace nix.nixDaemon = true; with services.nix-daemon.enable = true;.


I switched to a configuration that attempted to override some of the org.nix.nix-daemon plist keys, and the resulting plist file contained only the Label and the overridden key.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.nixos.nix-daemon</string>
    <key>SoftResourceLimits</key>
    <dict>
        <key>NumberOfFiles</key>
        <integer>10240</integer>
    </dict>
</dict>
</plist>

Plist xml is noisy; here's a simpler representation.

{ Label = "org.nixos.nix-daemon"
, SoftResourceLimits.NumberOfFiles = 10240
}

No matter what I tried, I was unable to load the file; here's an example.

> sudo -i sh -c 'launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'
Load failed: 5: Input/output error
Try running `launchctl bootstrap` as root for richer errors.

(I never saw a richer error.)

I ended up manually copying the relevant plist file from the nix store (via a profile link) to /Library/LaunchDaemons.

sudo install -m 444 \
  /nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist \
  /Library/LaunchDaemons/org.nixos.nix-daemon.plist

This worked; here's the contents of the plist file.

{ EnvironmentVariables.OBJC_DISABLE_INITIALIZE_FORK_SAFETY = "YES"
, KeepAlive = True
, Label = "org.nixos.nix-daemon"
, ProgramArguments =
  [ "/bin/sh"
  , "-c"
  , "/bin/wait4path /nix/var/nix/profiles/default/bin/nix-daemon && exec /nix/var/nix/profiles/default/bin/nix-daemon"
  ]
, RunAtLoad = True
, SoftResourceLimits.NumberOfFiles = 1048576
, StandardErrorPath = "/var/log/nix-daemon.log"
, StandardOutPath = "/dev/null"
}

With that, the launchctl load command worked.

However, as soon as I switched to the new configuration, the org.nixos.nix-daemon service was removed — and I'm not sure why. that required a change from nix.nixDaemon = true; to service.nix-daemon.enable = true;.

@fundon
Copy link

fundon commented Nov 12, 2023

@dbaynard thanks.

I used nix.nixDaemon = true; that will broke the daemon service.

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/how-to-update-nixpkgs/36563/9

@ryan4yin
Copy link

ryan4yin commented Dec 28, 2023

Same error here, and found I have a process that ran out of my cpu, which caused nix-daemon failed to response...
after killing that process, all things works just fine.

@debu99
Copy link

debu99 commented Mar 17, 2024

sudo -i sh -c 'launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'
sudo launchctl list | grep org.nixos
29402	0	org.nixos.nix-daemon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installer macos Nix on macOS, aka OS X, aka darwin
Projects
None yet
Development

No branches or pull requests