From d7653dfc6dea076ecbe00520c6137977e0fced35 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 1 May 2017 15:46:47 +0200 Subject: [PATCH] Remove $NIX_BUILD_HOOK and $NIX_CURRENT_LOAD This is to simplify remote build configuration. These environment variables predate nix.conf. The build hook now has a sensible default (namely build-remote). The current load is kept in the Nix state directory now. --- .../advanced-topics/distributed-builds.xml | 15 +- doc/manual/command-ref/env-common.xml | 133 ------------------ src/build-remote/build-remote.cc | 4 +- src/libstore/build.cc | 12 +- src/libstore/globals.hh | 3 + tests/remote-builds.nix | 1 - 6 files changed, 12 insertions(+), 156 deletions(-) diff --git a/doc/manual/advanced-topics/distributed-builds.xml b/doc/manual/advanced-topics/distributed-builds.xml index d5bc1c592..1957e1105 100644 --- a/doc/manual/advanced-topics/distributed-builds.xml +++ b/doc/manual/advanced-topics/distributed-builds.xml @@ -22,10 +22,7 @@ will call whenever it wants to build a derivation. The build hook will perform it in the usual way if possible, or it can accept it, in which case it is responsible for somehow getting the inputs of the build to another machine, doing the build there, and getting the -results back. The details of the build hook protocol are described in -the documentation of the NIX_BUILD_HOOK -variable. +results back. Remote machine configuration: <filename>remote-systems.conf</filename> @@ -103,14 +100,6 @@ requiredSystemFeatures = [ "kvm" ]; -You should also set up the environment variable -NIX_CURRENT_LOAD to point at a directory (e.g., -/var/run/nix/current-load) that -build-remote uses to remember how many builds -it is currently executing remotely. It doesn't look at the actual -load on the remote machine, so if you have multiple instances of Nix -running, they should use the same NIX_CURRENT_LOAD -file. Maybe in the future build-remote will -look at the actual remote load. + diff --git a/doc/manual/command-ref/env-common.xml b/doc/manual/command-ref/env-common.xml index c757cb17b..a83aeaf2e 100644 --- a/doc/manual/command-ref/env-common.xml +++ b/doc/manual/command-ref/env-common.xml @@ -148,139 +148,6 @@ $ mount -o bind /mnt/otherdisk/nix /nix -NIX_BUILD_HOOK - - - - Specifies the location of the build hook, - which is a program (typically some script) that Nix will call - whenever it wants to build a derivation. This is used to implement - distributed builds (see ). - - - - - - - - - NIX_REMOTE This variable should be set to diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 1ee8a625b..c41383bcf 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -140,7 +140,9 @@ int main (int argc, char * * argv) settings.buildTimeout = std::stoll(argv[3]); verbosity = (Verbosity) std::stoll(argv[4]); - currentLoad = getEnv("NIX_CURRENT_LOAD", "/run/nix/current-load"); + /* It would be more appropriate to use $XDG_RUNTIME_DIR, since + that gets cleared on reboot, but it wouldn't work on OS X. */ + currentLoad = settings.nixStateDir + "/current-load"; std::shared_ptr sshStore; AutoCloseFD bestSlotLock; diff --git a/src/libstore/build.cc b/src/libstore/build.cc index a0efd8804..9b3f799b9 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -583,11 +583,7 @@ struct HookInstance HookInstance::HookInstance() { - debug("starting build hook"); - - Path buildHook = getEnv("NIX_BUILD_HOOK"); - if (string(buildHook, 0, 1) != "/") buildHook = settings.nixLibexecDir + "/nix/" + buildHook; - buildHook = canonPath(buildHook); + debug("starting build hook ‘%s’", settings.buildHook); /* Create a pipe to get the output of the child. */ fromHook.create(); @@ -621,9 +617,9 @@ HookInstance::HookInstance() std::to_string(verbosity) }; - execv(buildHook.c_str(), stringsToCharPtrs(args).data()); + execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data()); - throw SysError(format("executing ‘%1%’") % buildHook); + throw SysError("executing ‘%s’", settings.buildHook); }); pid.setSeparatePG(true); @@ -1569,7 +1565,7 @@ void DerivationGoal::buildDone() HookReply DerivationGoal::tryBuildHook() { - if (!settings.useBuildHook || getEnv("NIX_BUILD_HOOK") == "" || !useDerivation) return rpDecline; + if (!settings.useBuildHook || !useDerivation) return rpDecline; if (!worker.hook) worker.hook = std::make_unique(); diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index b4f44de2e..25cc3e068 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -127,6 +127,9 @@ public: Setting useBuildHook{this, true, "remote-builds", "Whether to use build hooks (for distributed builds)."}; + PathSetting buildHook{this, true, nixLibexecDir + "/nix/build-remote", "build-hook", + "The path of the helper program that executes builds to remote machines."}; + Setting reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space", "Amount of reserved disk space for the garbage collector."}; diff --git a/tests/remote-builds.nix b/tests/remote-builds.nix index 63aaa4d88..39bd090e4 100644 --- a/tests/remote-builds.nix +++ b/tests/remote-builds.nix @@ -43,7 +43,6 @@ in { config, pkgs, ... }: { nix.maxJobs = 0; # force remote building nix.distributedBuilds = true; - nix.envVars = pkgs.lib.mkAfter { NIX_BUILD_HOOK = "${nix}/libexec/nix/build-remote"; }; nix.buildMachines = [ { hostName = "slave1"; sshUser = "root";