From a413594baf8633b59648e69f66dcf44bd0ad0b6c Mon Sep 17 00:00:00 2001 From: Rovanion Luckey Date: Thu, 23 Jan 2020 14:48:53 +0100 Subject: [PATCH 1/4] installer: Handle edge case where the nix-daemon is already running on the system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/install-systemd-multi-user.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-systemd-multi-user.sh b/scripts/install-systemd-multi-user.sh index bef3ac4f9..e0201d53b 100755 --- a/scripts/install-systemd-multi-user.sh +++ b/scripts/install-systemd-multi-user.sh @@ -88,7 +88,7 @@ poly_configure_nix_daemon_service() { systemctl start nix-daemon.socket _sudo "to start the nix-daemon.service" \ - systemctl start nix-daemon.service + systemctl restart nix-daemon.service } From 46992e71a1c596cb9b25a615738fb0b18e63c227 Mon Sep 17 00:00:00 2001 From: Calvin Loncaric Date: Sun, 26 Jan 2020 17:22:47 -0800 Subject: [PATCH 2/4] Document that autoconf is a dependency --- doc/manual/installation/prerequisites-source.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/manual/installation/prerequisites-source.xml b/doc/manual/installation/prerequisites-source.xml index e7bdcf966..fa6da9b1e 100644 --- a/doc/manual/installation/prerequisites-source.xml +++ b/doc/manual/installation/prerequisites-source.xml @@ -8,6 +8,14 @@ + GNU Autoconf + () + and the autoconf-archive macro collection + (). + These are only needed to run the bootstrap script, and are not necessary + if your source distribution came with a pre-built + ./configure script. + GNU Make. Bash Shell. The ./configure script From d78141a886383c38afb9fb294eec6fac0b74986e Mon Sep 17 00:00:00 2001 From: Carlos D Date: Fri, 14 Feb 2020 16:11:22 +1100 Subject: [PATCH 3/4] Pass through http proxy env vars in pure shell --- src/nix-build/nix-build.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index 205165a4c..e602ea555 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -97,7 +97,11 @@ static void _main(int argc, char * * argv) std::string outLink = "./result"; // List of environment variables kept for --pure - std::set keepVars{"HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL"}; + std::set keepVars{ + "HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", + "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL", + "http_proxy", "https_proxy", "ftp_proxy", "all_proxy", "no_proxy" + }; Strings args; for (int i = 1; i < argc; ++i) From f2a03acf3f42140f40fa5141b2b6ea94a554df64 Mon Sep 17 00:00:00 2001 From: Albert Safin Date: Fri, 17 Jan 2020 06:44:00 +0000 Subject: [PATCH 4/4] nix-shell: clean up the tmpDir and escape variables The problem fixed: each nix-shell invocation creates a new temporary directory (`/tmp/nix-shell-*`) and never cleans up. And while I'm here, shellescape all variables inlined into the rcfile. See what might happen without escaping: $ export TZ="';echo pwned'" $ nix-shell -p hello --run hello pwned Hello, world! --- src/nix-build/nix-build.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index 205165a4c..d9bec431e 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -423,13 +423,18 @@ static void _main(int argc, char * * argv) lose the current $PATH directories. */ auto rcfile = (Path) tmpDir + "/rc"; writeFile(rcfile, fmt( - (keepTmp ? "" : "rm -rf '%1%'; "s) + + R"(_nix_shell_clean_tmpdir() { rm -rf %1%; }; )"s + + (keepTmp ? + "trap _nix_shell_clean_tmpdir EXIT; " + "exitHooks+=(_nix_shell_clean_tmpdir); " + "failureHooks+=(_nix_shell_clean_tmpdir); ": + "_nix_shell_clean_tmpdir; ") + (pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;") + "%2%" "dontAddDisableDepTrack=1; " "[ -e $stdenv/setup ] && source $stdenv/setup; " "%3%" - "PATH=\"%4%:$PATH\"; " + "PATH=%4%:\"$PATH\"; " "SHELL=%5%; " "set +e; " R"s([ -n "$PS1" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s" @@ -438,12 +443,12 @@ static void _main(int argc, char * * argv) "shopt -u nullglob; " "unset TZ; %6%" "%7%", - (Path) tmpDir, + shellEscape(tmpDir), (pure ? "" : "p=$PATH; "), (pure ? "" : "PATH=$PATH:$p; unset p; "), - dirOf(*shell), - *shell, - (getenv("TZ") ? (string("export TZ='") + getenv("TZ") + "'; ") : ""), + shellEscape(dirOf(*shell)), + shellEscape(*shell), + (getenv("TZ") ? (string("export TZ=") + shellEscape(getenv("TZ")) + "; ") : ""), envCommand)); Strings envStrs;