nix/scripts
Rovanion Luckey c4702f938c
installer: Handle edge case where the nix-daemon is already running on the system
On a systemd-based Linux distribution: If the user has previously had multi-user Nix installed on the system, removed it and then reinstalled multi-user Nix again the old nix-daemon.service will still be running when `scripts/install-systemd-multi-user.sh` tries to start it which results in nothing being done and the old daemon continuing its run.

When a normal user then tries to use Nix through the daemon the nix binary will fail to connect to the nix-daemon as it does not belong to the currently installed Nix system. See below for steps to reproduce the issue that motivated this change.

$ sh <(curl https://nixos.org/nix/install) --daemon

$ sudo rm -rf /etc/nix /nix /root/.nix-profile /root/.nix-defexpr /root/.nix-channels /home/nix-installer/.nix-profile /home/nix-installer/.nix-defexpr /home/nix-installer/.nix-channels ~/.nix-channels ~/.nix-defexpr/ ~/.nix-profile /etc/profile.d/nix.sh.backup-before-nix /etc/profile.d/nix.sh; sed -i '/added by Nix installer$/d' ~/.bash_profile

$ unset NIX_REMOTE

$ sh <(curl https://nixos.org/nix/install) --daemon

└$ export NIX_REMOTE=daemon

└$ nix-env -iA nixpkgs.hello
installing 'hello-2.10'
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)

└$ sudo systemctl restart nix-daemon.service

└$ nix-env -iA nixpkgs.hello
installing 'hello-2.10'
these paths will be fetched (6.09 MiB download, 27.04 MiB unpacked):
  /nix/store/2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10
  /nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27
copying path '/nix/store/aag9d1y4wcddzzrpfmfp9lcmc7skd7jk-glibc-2.27' from 'https://cache.nixos.org'...
copying path '/nix/store/2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10' from 'https://cache.nixos.org'...
building '/nix/store/w9adagg6vlikr799nkkqc9la5hbbpgmi-user-environment.drv'...
created 2 symlinks in user environment

(cherry picked from commit a413594baf)
Signed-off-by: Domen Kožar <domen@dev.si>
2020-05-26 11:39:02 +02:00
..
install-darwin-multi-user.sh Copy instead of linking launch agent 2020-01-04 14:06:29 +01:00
install-multi-user.sh installer: Fix terminal colors. 2020-04-10 10:49:33 +02:00
install-nix-from-closure.sh Pass -P to cp to preserve symlinks 2020-05-26 11:39:01 +02:00
install-systemd-multi-user.sh installer: Handle edge case where the nix-daemon is already running on the system 2020-05-26 11:39:02 +02:00
install.in Pass -J to tar for xz decompression 2020-05-26 11:39:01 +02:00
local.mk Pull nix-profile-daemon from 1.11 2017-10-16 14:51:39 -04:00
nix-http-export.cgi.in Replace wrong (w.r.t. PATH) sed call with in-shell substitution 2009-02-19 20:46:45 +00:00
nix-profile-daemon.sh.in Remove $NIX_USER_PROFILE_DIR 2020-05-26 11:39:01 +02:00
nix-profile.sh.in Remove $NIX_USER_PROFILE_DIR 2020-05-26 11:39:01 +02:00
nix-reduce-build.in Add support for ‘make installcheck’ 2013-11-25 18:47:03 +01:00