From f3dc4e9228a23dd6ab49e081be5cd43a68092ab8 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 14 Feb 2025 17:57:12 -0500 Subject: [PATCH] WIP ssh-ng:// --- flake.lock | 8 ++--- flake.nix | 2 +- src/hydra-queue-runner/build-remote.cc | 33 ++++++++++---------- src/hydra-queue-runner/builder.cc | 18 ++++------- src/hydra-queue-runner/hydra-queue-runner.cc | 2 +- src/hydra-queue-runner/state.hh | 7 ++--- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/flake.lock b/flake.lock index 8217d168..7d1bcbce 100644 --- a/flake.lock +++ b/flake.lock @@ -13,16 +13,16 @@ "nixpkgs-regression": [] }, "locked": { - "lastModified": 1739570697, - "narHash": "sha256-n5kdS1C24tlJxDV6Wm1iBlyvGk+p0gMXRcWVCAipYLs=", + "lastModified": 1739571938, + "narHash": "sha256-NlaLAed/xei6RWpU2HIIbDjILRC4l1NIfGeyrn7ALQs=", "owner": "NixOS", "repo": "nix", - "rev": "5eade4825221d3284fc6555cb20de2c7aa171d72", + "rev": "ffc649d2eabdd3e678b5bcc211dd59fd06debf3e", "type": "github" }, "original": { "owner": "NixOS", - "ref": "legacy-ssh-extensions-for-hydra", + "ref": "ssh-ng-extensions-for-hydra", "repo": "nix", "type": "github" } diff --git a/flake.nix b/flake.nix index 932bf1b9..244d3353 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11-small"; inputs.nix = { - url = "github:NixOS/nix/legacy-ssh-extensions-for-hydra"; + url = "github:NixOS/nix/ssh-ng-extensions-for-hydra"; inputs.nixpkgs.follows = "nixpkgs"; # hide nix dev tooling from our lock file diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index 275ce612..b99bb550 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -7,7 +7,7 @@ #include "build-result.hh" #include "path.hh" -#include "legacy-ssh-store.hh" +#include "ssh-store.hh" #include "serve-protocol.hh" #include "state.hh" #include "current-process.hh" @@ -119,11 +119,10 @@ static BuildResult performBuild( Store & localStore, StorePath drvPath, const BasicDerivation & drv, - const ServeProto::BuildOptions & options, counter & nrStepsBuilding ) { - auto kont = conn.store->buildDerivationAsync(drvPath, drv, options); + auto kont = conn.store->buildDerivationAsync(drvPath, drv, bmNormal); BuildResult result; @@ -238,7 +237,6 @@ void RemoteResult::updateWithBuildResult(const nix::BuildResult & buildResult) void State::buildRemote(ref destStore, ::Machine::ptr machine, Step::ptr step, - const ServeProto::BuildOptions & buildOptions, RemoteResult & result, std::shared_ptr activeStep, std::function updateStep, NarMemberDatas & narMembers) @@ -258,23 +256,26 @@ void State::buildRemote(ref destStore, .machine = machine, .store = [&]{ auto * pSpecified = std::get_if(&machine->storeUri.variant); - if (!pSpecified || pSpecified->scheme != "ssh") { - throw Error("Currently, only (legacy-)ssh stores are supported!"); + if (!pSpecified || pSpecified->scheme != "ssh-ng") { + throw Error("Currently, only ssh-ng:// stores are supported!"); } - auto remoteStore = machine->openStore().dynamic_pointer_cast(); + auto remoteStore = machine->openStore().dynamic_pointer_cast(); + auto remoteStoreConfig = std::dynamic_pointer_cast(remoteStore); assert(remoteStore); if (machine->isLocalhost()) { - auto rp_new = remoteStore->remoteProgram.get(); + auto rp_new = remoteStoreConfig->remoteProgram.get(); rp_new.push_back("--builders"); rp_new.push_back(""); - const_cast &>(remoteStore->remoteProgram).assign(rp_new); + const_cast &>(remoteStoreConfig->remoteProgram).assign(rp_new); } - remoteStore->extraSshArgs = { + remoteStoreConfig->extraSshArgs = { "-a", "-oBatchMode=yes", "-oConnectTimeout=60", "-oTCPKeepAlive=yes" }; - const_cast &>(remoteStore->logFD).assign(logFD.get()); + + // TODO logging + //const_cast &>(remoteStore->logFD).assign(logFD.get()); return nix::ref{remoteStore}; }(), @@ -283,12 +284,10 @@ void State::buildRemote(ref destStore, { auto activeStepState(activeStep->state_.lock()); if (activeStepState->cancelled) throw Error("step cancelled"); - activeStepState->pid = conn.store->getConnectionPid(); } Finally clearPid([&]() { auto activeStepState(activeStep->state_.lock()); - activeStepState->pid = -1; /* FIXME: there is a slight race here with step cancellation in State::processQueueChange(), which @@ -299,9 +298,10 @@ void State::buildRemote(ref destStore, }); Finally updateStats([&]() { - auto stats = conn.store->getConnectionStats(); - bytesReceived += stats.bytesReceived; - bytesSent += stats.bytesSent; + // TODO + //auto stats = conn.store->getConnectionStats(); + //bytesReceived += stats.bytesReceived; + //bytesSent += stats.bytesSent; }); { @@ -341,7 +341,6 @@ void State::buildRemote(ref destStore, *localStore, step->drvPath, resolvedDrv, - buildOptions, nrStepsBuilding ); diff --git a/src/hydra-queue-runner/builder.cc b/src/hydra-queue-runner/builder.cc index 4bc00f0c..22b91420 100644 --- a/src/hydra-queue-runner/builder.cc +++ b/src/hydra-queue-runner/builder.cc @@ -98,13 +98,6 @@ State::StepResult State::doBuildStep(nix::ref destStore, it). */ BuildID buildId; std::optional buildDrvPath; - // Other fields set below - nix::ServeProto::BuildOptions buildOptions { - .maxLogSize = maxLogSize, - .nrRepeats = step->isDeterministic ? 1u : 0u, - .enforceDeterminism = step->isDeterministic, - .keepFailed = false, - }; auto conn(dbPool.get()); @@ -139,18 +132,19 @@ State::StepResult State::doBuildStep(nix::ref destStore, { auto i = jobsetRepeats.find(std::make_pair(build2->projectName, build2->jobsetName)); if (i != jobsetRepeats.end()) - buildOptions.nrRepeats = std::max(buildOptions.nrRepeats, i->second); + warn("jobset repeats is deprecated; nix stopped supporting this correctly a long time ago."); } } if (!build) build = *dependents.begin(); buildId = build->id; buildDrvPath = build->drvPath; - buildOptions.maxSilentTime = build->maxSilentTime; - buildOptions.buildTimeout = build->buildTimeout; + settings.maxLogSize = maxLogSize; + settings.maxSilentTime = build->maxSilentTime; + settings.buildTimeout = build->buildTimeout; printInfo("performing step ā€˜%s’ %d times on ā€˜%s’ (needed by build %d and %d others)", - localStore->printStorePath(step->drvPath), buildOptions.nrRepeats + 1, machine->storeUri.render(), buildId, (dependents.size() - 1)); + localStore->printStorePath(step->drvPath), 1, machine->storeUri.render(), buildId, (dependents.size() - 1)); } if (!buildOneDone) @@ -211,7 +205,7 @@ State::StepResult State::doBuildStep(nix::ref destStore, try { /* FIXME: referring builds may have conflicting timeouts. */ - buildRemote(destStore, machine, step, buildOptions, result, activeStep, updateStep, narMembers); + buildRemote(destStore, machine, step, result, activeStep, updateStep, narMembers); } catch (Error & e) { if (activeStep->state_.lock()->cancelled) { printInfo("marking step %d of build %d as cancelled", stepNr, buildId); diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 99411f9f..82ff3b3b 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -182,7 +182,7 @@ void State::monitorMachinesFile() getEnv("NIX_REMOTE_SYSTEMS").value_or(pathExists(defaultMachinesFile) ? defaultMachinesFile : ""), ":"); if (machinesFiles.empty()) { - parseMachines("localhost " + + parseMachines("ssh-ng://localhost " + (settings.thisSystem == "x86_64-linux" ? "x86_64-linux,i686-linux" : settings.thisSystem.get()) + " - " + std::to_string(settings.maxBuildJobs) + " 1 " + concatStringsSep(",", StoreConfig::getDefaultSystemFeatures())); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index e2d31434..8c5958a7 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -20,7 +20,7 @@ #include "store-api.hh" #include "sync.hh" #include "nar-extractor.hh" -#include "legacy-ssh-store.hh" +#include "ssh-store.hh" #include "machines.hh" @@ -294,12 +294,12 @@ struct Machine : nix::Machine // Backpointer to the machine ptr machine; // Opened store - nix::ref store; + nix::ref store; }; }; -class HydraConfig; +struct HydraConfig; class State @@ -542,7 +542,6 @@ private: void buildRemote(nix::ref destStore, Machine::ptr machine, Step::ptr step, - const nix::ServeProto::BuildOptions & buildOptions, RemoteResult & result, std::shared_ptr activeStep, std::function updateStep, NarMemberDatas & narMembers);