hydra-queue-runner: Support running in a NixOS container

In a NixOS container, cmdBuildDerivation doesn't work because we're
not privileged. But we also don't need it because the store already
has the derivation.

Also, don't copy from/to the store since this gives errors about
missing signatures.
This commit is contained in:
Eelco Dolstra 2019-09-25 17:26:03 +02:00
parent 554bb7d9ce
commit d4b4255dd2
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 17 additions and 7 deletions

View file

@ -48,7 +48,7 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
throw SysError("cannot dup stderr"); throw SysError("cannot dup stderr");
Strings argv; Strings argv;
if (machine->sshName == "localhost") { if (machine->isLocalhost()) {
pgmName = "nix-store"; pgmName = "nix-store";
argv = {"nix-store", "--serve", "--write"}; argv = {"nix-store", "--serve", "--write"};
} }
@ -190,7 +190,11 @@ void State::buildRemote(ref<Store> destStore,
remoteVersion = readInt(from); remoteVersion = readInt(from);
if (GET_PROTOCOL_MAJOR(remoteVersion) != 0x200) if (GET_PROTOCOL_MAJOR(remoteVersion) != 0x200)
throw Error(format("unsupported nix-store --serve protocol version on %1%") % machine->sshName); throw Error(format("unsupported nix-store --serve protocol version on %1%") % machine->sshName);
if (GET_PROTOCOL_MINOR(remoteVersion) >= 1) // Always send the derivation to localhost, since it's a
// no-op anyway but we might not be privileged to use
// cmdBuildDerivation (e.g. if we're running in a NixOS
// container).
if (GET_PROTOCOL_MINOR(remoteVersion) >= 1 && !machine->isLocalhost())
sendDerivation = false; sendDerivation = false;
if (GET_PROTOCOL_MINOR(remoteVersion) < 3 && repeats > 0) if (GET_PROTOCOL_MINOR(remoteVersion) < 3 && repeats > 0)
throw Error("machine %1% does not support repeating a build; please upgrade it to Nix 1.12", machine->sshName); throw Error("machine %1% does not support repeating a build; please upgrade it to Nix 1.12", machine->sshName);
@ -236,10 +240,11 @@ void State::buildRemote(ref<Store> destStore,
a no-op for regular stores, but for the binary cache store, a no-op for regular stores, but for the binary cache store,
this will copy the inputs to the binary cache from the local this will copy the inputs to the binary cache from the local
store. */ store. */
copyClosure(ref<Store>(localStore), destStore, step->drv.inputSrcs, NoRepair, NoCheckSigs); if (localStore != std::shared_ptr<Store>(destStore))
copyClosure(ref<Store>(localStore), destStore, step->drv.inputSrcs, NoRepair, NoCheckSigs);
/* Copy the input closure. */ /* Copy the input closure. */
if (/* machine->sshName != "localhost" */ true) { if (!machine->isLocalhost()) {
auto mc1 = std::make_shared<MaintainCount<counter>>(nrStepsWaiting); auto mc1 = std::make_shared<MaintainCount<counter>>(nrStepsWaiting);
mc1.reset(); mc1.reset();
MaintainCount<counter> mc2(nrStepsCopyingTo); MaintainCount<counter> mc2(nrStepsCopyingTo);
@ -381,7 +386,9 @@ void State::buildRemote(ref<Store> destStore,
} }
/* Copy the output paths. */ /* Copy the output paths. */
if (/* machine->sshName != "localhost" */ true) { result.accessor = destStore->getFSAccessor();
if (!machine->isLocalhost() || localStore != std::shared_ptr<Store>(destStore)) {
updateStep(ssReceivingOutputs); updateStep(ssReceivingOutputs);
MaintainCount<counter> mc(nrStepsCopyingFrom); MaintainCount<counter> mc(nrStepsCopyingFrom);
@ -427,8 +434,6 @@ void State::buildRemote(ref<Store> destStore,
printMsg(lvlError, format("warning: had to wait %d ms for %d memory tokens for %s") printMsg(lvlError, format("warning: had to wait %d ms for %d memory tokens for %s")
% resMs % totalNarSize % step->drvPath); % resMs % totalNarSize % step->drvPath);
result.accessor = destStore->getFSAccessor();
to << cmdExportPaths << 0 << outputs; to << cmdExportPaths << 0 << outputs;
to.flush(); to.flush();
destStore->importPaths(from, result.accessor, NoCheckSigs); destStore->importPaths(from, result.accessor, NoCheckSigs);

View file

@ -274,6 +274,11 @@ struct Machine
return true; return true;
} }
bool isLocalhost()
{
return sshName == "localhost";
}
}; };