diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 50732d5670b..7e615acbfed 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -623,6 +623,28 @@ void LocalStore::registerDrvOutput(const DrvOutputId& id, const DrvOutputInfo & void LocalStore::registerDrvOutput_(State & state, const StorePath & deriver, const string & outputName, const StorePath & output) { + // Ensure that we don't register a boguous derivation output. + debug("Checking the validiy of the drv output '%s!%s'", printStorePath(deriver), outputName); + if (!isValidPath_(state, deriver)) + settings.requireExperimentalFeature("ca-derivations"); + else { + // Can't use `readDerivation` here as we already hold the lock on the db + auto matchingDrv = parseDerivation( + *this, + readFile(Store::toRealPath(deriver)), + Derivation::nameFromPath(deriver) + ); + auto outputsFromDrv = matchingDrv.outputsAndOptPaths(*this); + auto currentOutputFromDrv = outputsFromDrv.find(outputName); + assert (currentOutputFromDrv != outputsFromDrv.end()); + if (!currentOutputFromDrv->second.second.has_value()) { + // Floating-ca or dependent thereof + settings.requireExperimentalFeature("ca-derivations"); + } else { + assert (*currentOutputFromDrv->second.second == output); + } + } + retrySQLite([&]() { state.stmtAddDerivationOutput.use() (printStorePath(deriver))