diff options
Diffstat (limited to 'src/build-remote/build-remote.cc')
-rw-r--r-- | src/build-remote/build-remote.cc | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 9a0e9f08d..f784b5160 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -17,7 +17,7 @@ #include "store-api.hh" #include "derivations.hh" #include "local-store.hh" -#include "../nix/legacy.hh" +#include "legacy.hh" using namespace nix; using std::cin; @@ -53,6 +53,9 @@ static int main_build_remote(int argc, char * * argv) unsetenv("DISPLAY"); unsetenv("SSH_ASKPASS"); + /* If we ever use the common args framework, make sure to + remove initPlugins below and initialize settings first. + */ if (argc != 2) throw UsageError("called without required arguments"); @@ -71,11 +74,15 @@ static int main_build_remote(int argc, char * * argv) initPlugins(); - auto store = openStore().cast<LocalStore>(); + auto store = openStore(); /* It would be more appropriate to use $XDG_RUNTIME_DIR, since that gets cleared on reboot, but it wouldn't work on macOS. */ - currentLoad = store->stateDir + "/current-load"; + auto currentLoadName = "/current-load"; + if (auto localStore = store.dynamic_pointer_cast<LocalFSStore>()) + currentLoad = std::string { localStore->stateDir } + currentLoadName; + else + currentLoad = settings.nixStateDir + currentLoadName; std::shared_ptr<Store> sshStore; AutoCloseFD bestSlotLock; @@ -172,13 +179,14 @@ static int main_build_remote(int argc, char * * argv) else { // build the hint template. - string hintstring = "derivation: %s\nrequired (system, features): (%s, %s)"; - hintstring += "\n%s available machines:"; - hintstring += "\n(systems, maxjobs, supportedFeatures, mandatoryFeatures)"; + string errorText = + "Failed to find a machine for remote build!\n" + "derivation: %s\nrequired (system, features): (%s, %s)"; + errorText += "\n%s available machines:"; + errorText += "\n(systems, maxjobs, supportedFeatures, mandatoryFeatures)"; - for (unsigned int i = 0; i < machines.size(); ++i) { - hintstring += "\n(%s, %s, %s, %s)"; - } + for (unsigned int i = 0; i < machines.size(); ++i) + errorText += "\n(%s, %s, %s, %s)"; // add the template values. string drvstr; @@ -187,25 +195,21 @@ static int main_build_remote(int argc, char * * argv) else drvstr = "<unknown>"; - auto hint = hintformat(hintstring); - hint - % drvstr - % neededSystem - % concatStringsSep<StringSet>(", ", requiredFeatures) - % machines.size(); - - for (auto & m : machines) { - hint % concatStringsSep<vector<string>>(", ", m.systemTypes) - % m.maxJobs - % concatStringsSep<StringSet>(", ", m.supportedFeatures) - % concatStringsSep<StringSet>(", ", m.mandatoryFeatures); - } + auto error = hintformat(errorText); + error + % drvstr + % neededSystem + % concatStringsSep<StringSet>(", ", requiredFeatures) + % machines.size(); + + for (auto & m : machines) + error + % concatStringsSep<vector<string>>(", ", m.systemTypes) + % m.maxJobs + % concatStringsSep<StringSet>(", ", m.supportedFeatures) + % concatStringsSep<StringSet>(", ", m.mandatoryFeatures); - logErrorInfo(lvlInfo, { - .name = "Remote build", - .description = "Failed to find a machine for remote build!", - .hint = hint - }); + printMsg(canBuildLocally ? lvlChatty : lvlWarn, error); std::cerr << "# decline\n"; } @@ -230,12 +234,9 @@ static int main_build_remote(int argc, char * * argv) } catch (std::exception & e) { auto msg = chomp(drainFD(5, false)); - logError({ - .name = "Remote build", - .hint = hintfmt("cannot build on '%s': %s%s", - bestMachine->storeUri, e.what(), - (msg.empty() ? "" : ": " + msg)) - }); + printError("cannot build on '%s': %s%s", + bestMachine->storeUri, e.what(), + msg.empty() ? "" : ": " + msg); bestMachine->enabled = false; continue; } @@ -288,8 +289,9 @@ connected: if (!missing.empty()) { Activity act(*logger, lvlTalkative, actUnknown, fmt("copying outputs from '%s'", storeUri)); - for (auto & i : missing) - store->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */ + if (auto localStore = store.dynamic_pointer_cast<LocalStore>()) + for (auto & i : missing) + localStore->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */ copyPaths(ref<Store>(sshStore), store, missing, NoRepair, NoCheckSigs, NoSubstitute); } |