NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.94k stars 1.53k forks source link

nix 2.0 on macOS High Sierra - error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket' #1980

Open teuffy opened 6 years ago

teuffy commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago
peti commented 6 years ago

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 commented 6 years ago

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

sudo launchctl list | grep org.nixos
teuffy commented 6 years ago

sudo launchctl list | grep org.nixos

119 0 org.nixos.nix-daemon

jeffreyrosenbluth commented 6 years ago

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

LnL7 commented 6 years ago

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

sudo launchctl kickstart -k system/org.nixos.nix-daemon
Tehnix commented 6 years ago

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 commented 6 years ago

Ah, a full reboot worked for me as well.

LnL7 commented 6 years ago

That's odd, is https://github.com/NixOS/nix/pull/1920/commits/05cb8e5c5a954fa999ac5156cdf19148a05fdb2b not in 2.0?

robsimmons commented 6 years ago

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

shlevy commented 6 years ago

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

gbersac commented 6 years ago

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 commented 6 years ago

@Tehnix

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

nekoniaow commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

zhujinxuan commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago
$ 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 commented 4 years ago

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[bot] commented 3 years ago

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

stale[bot] commented 3 years ago

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

Serif-7 commented 1 year ago

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.

alessandrocandolini commented 1 year ago

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 commented 1 year ago

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

jonasschultheiss commented 1 year ago

ah nevermind, just had to restart my mac

dbaynard commented 1 year ago

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 https://github.com/NixOS/nix/issues/6499#issuecomment-1497486104 — 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 commented 1 year ago

@dbaynard thanks.

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

nixos-discourse commented 11 months ago

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 commented 11 months ago

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 commented 8 months ago
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
portothree commented 2 months ago
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

Had the same issue on Sequoia, and this fixes it. Thanks!

rtlong commented 1 month ago

I ran into this and in my case the issue was my configuration overwrote my trusted-users list and the new value didn't include my user. I had to add my user to the wheel group (which was listed in trusted-users and restart.