Ensure resolved CA derivations are written

so we can link outputs to deriver and thus properly cache.
This commit is contained in:
John Ericson 2020-09-09 19:13:21 +00:00
parent 7fdbb377ba
commit 2741fffa35
2 changed files with 21 additions and 13 deletions

View file

@ -4298,11 +4298,13 @@ void DerivationGoal::registerOutputs()
/* Register each output path as valid, and register the sets of /* Register each output path as valid, and register the sets of
paths referenced by each of them. If there are cycles in the paths referenced by each of them. If there are cycles in the
outputs, this will fail. */ outputs, this will fail. */
ValidPathInfos infos2; {
for (auto & [outputName, newInfo] : infos) { ValidPathInfos infos2;
infos2.push_back(newInfo); for (auto & [outputName, newInfo] : infos) {
infos2.push_back(newInfo);
}
worker.store.registerValidPaths(infos2);
} }
worker.store.registerValidPaths(infos2);
/* In case of a fixed-output derivation hash mismatch, throw an /* In case of a fixed-output derivation hash mismatch, throw an
exception now that we have registered the output as valid. */ exception now that we have registered the output as valid. */
@ -4314,16 +4316,21 @@ void DerivationGoal::registerOutputs()
means it's safe to link the derivation to the output hash. We must do means it's safe to link the derivation to the output hash. We must do
that for floating CA derivations, which otherwise couldn't be cached, that for floating CA derivations, which otherwise couldn't be cached,
but it's fine to do in all cases. */ but it's fine to do in all cases. */
for (auto & [outputName, newInfo] : infos) { bool isCaFloating = drv->type() == DerivationType::CAFloating;
if (useDerivation)
worker.store.linkDeriverToPath(drvPath, outputName, newInfo.path); auto drvPath2 = drvPath;
else { if (!useDerivation && isCaFloating) {
/* Once a floating CA derivations reaches this point, it must /* Once a floating CA derivations reaches this point, it
already be resolved, drvPath the basic derivation path, and must already be resolved, so we don't bother trying to
a file existsing at that path for sake of the DB's foreign key. */ downcast drv to get would would just be an empty
assert(drv->type() != DerivationType::CAFloating); inputDrvs field. */
} Derivation drv2 { *drv };
drvPath2 = writeDerivation(worker.store, drv2);
} }
if (useDerivation || isCaFloating)
for (auto & [outputName, newInfo] : infos)
worker.store.linkDeriverToPath(drvPath, outputName, newInfo.path);
} }

View file

@ -136,6 +136,7 @@ struct Derivation : BasicDerivation
std::optional<BasicDerivation> tryResolve(Store & store); std::optional<BasicDerivation> tryResolve(Store & store);
Derivation() = default; Derivation() = default;
Derivation(const BasicDerivation & bd) : BasicDerivation(bd) { }
Derivation(BasicDerivation && bd) : BasicDerivation(std::move(bd)) { } Derivation(BasicDerivation && bd) : BasicDerivation(std::move(bd)) { }
}; };