1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 22:42:41 +01: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

@ -855,16 +855,24 @@ StorePathSet LocalStore::querySubstitutablePaths(const StorePathSet & paths)
void LocalStore::querySubstitutablePathInfos(const StorePathSet & paths,
SubstitutablePathInfos & infos)
SubstitutablePathInfos & infos, std::map<std::string, std::string> pathsCA)
{
if (!settings.useSubstitutes) return;
for (auto & sub : getDefaultSubstituters()) {
if (sub->storeDir != storeDir) continue;
for (auto & path : paths) {
if (infos.count(path)) continue;
for (auto & path_ : paths) {
auto path(path_.clone());
debug("checking substituter '%s' for path '%s'", sub->getUri(), printStorePath(path));
try {
auto info = sub->queryPathInfo(path);
auto ca = pathsCA.find(printStorePath(path));
if (sub->storeDir != storeDir && info->references.empty() && ca != pathsCA.end()) {
if (!hasPrefix(ca->second, "fixed:"))
continue;
// recompute store path so that we can use a fixed output ca
path = sub->makeStorePath("output:out", hashString(htSHA256, ca->second), path.name());
} else continue;
auto narInfo = std::dynamic_pointer_cast<const NarInfo>(
std::shared_ptr<const ValidPathInfo>(info));
infos.insert_or_assign(path.clone(), SubstitutablePathInfo{