1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

Allow substituting from different storeDir

Substituters can substitute from one store dir to another with a
little bit of help. The store api just needs to have a CA so it can
recompute the store path based on the new store dir. We can only do
this for fixed output derivations with no references, though.
This commit is contained in:
Matthew Bauer 2020-06-12 09:49:09 -05:00
parent d558fb98f6
commit 79c169d1c6
7 changed files with 50 additions and 9 deletions

View file

@ -108,6 +108,27 @@ void Store::computeFSClosure(const StorePath & startPath,
}
static std::optional<std::string> getDerivationCA(ref<Derivation> drv)
{
auto outputHashMode = drv->env.find("outputHashMode");
auto outputHashAlgo = drv->env.find("outputHashAlgo");
auto outputHash = drv->env.find("outputHash");
if (outputHashMode != drv->env.end() && outputHashAlgo != drv->env.end() && outputHash != drv->env.end()) {
auto ht = parseHashType(outputHashAlgo->second);
auto h = Hash(outputHash->second, ht);
FileIngestionMethod ingestionMethod;
if (outputHashMode->second == "recursive")
ingestionMethod = FileIngestionMethod::Recursive;
else if (outputHashMode->second == "flat")
ingestionMethod = FileIngestionMethod::Flat;
else
throw Error("unknown ingestion method: '%s'", outputHashMode->second);
return makeFixedOutputCA(ingestionMethod, h);
}
return std::nullopt;
}
void Store::queryMissing(const std::vector<StorePathWithOutputs> & targets,
StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_,
unsigned long long & downloadSize_, unsigned long long & narSize_)
@ -159,7 +180,11 @@ void Store::queryMissing(const std::vector<StorePathWithOutputs> & targets,
SubstitutablePathInfos infos;
StorePathSet paths; // FIXME
paths.insert(outPath.clone());
querySubstitutablePathInfos(paths, infos);
std::map<std::string, std::string> pathsCA = {};
if (auto ca = getDerivationCA(drv))
pathsCA.insert({outPathS, *ca});
querySubstitutablePathInfos(paths, infos, pathsCA);
if (infos.empty()) {
drvState_->lock()->done = true;