mirror of
https://github.com/NixOS/nix.git
synced 2025-11-25 11:49:35 +01:00
Fix NAR hash checking for fetchGit with lazy tees
If a NAR hash is specified, we should probably check it. Unfortunately, for now this has the side effect of forcing NAR hash checking of any input that has a NAR hash.
This commit is contained in:
parent
b067e6566f
commit
fca291afc3
1 changed files with 19 additions and 16 deletions
|
|
@ -77,25 +77,28 @@ StorePath EvalState::mountInput(
|
||||||
|
|
||||||
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
|
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
|
||||||
|
|
||||||
|
std::optional<Hash> _narHash;
|
||||||
|
|
||||||
|
auto getNarHash = [&]()
|
||||||
|
{
|
||||||
|
if (!_narHash)
|
||||||
|
// FIXME: use fetchToStore to make it cache this
|
||||||
|
_narHash = accessor->hashPath(CanonPath::root);
|
||||||
|
return _narHash;
|
||||||
|
};
|
||||||
|
|
||||||
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
|
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
|
||||||
|
|
||||||
if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash()) {
|
if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash())
|
||||||
// FIXME: use fetchToStore to make it cache this
|
input.attrs.insert_or_assign("narHash", getNarHash()->to_string(HashFormat::SRI, true));
|
||||||
auto narHash = accessor->hashPath(CanonPath::root);
|
|
||||||
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: what to do with the NAR hash in lazy mode?
|
if (originalInput.getNarHash() && *getNarHash() != *originalInput.getNarHash())
|
||||||
if (!settings.lazyTrees && originalInput.getNarHash()) {
|
throw Error(
|
||||||
auto expected = originalInput.computeStorePath(*store);
|
(unsigned int) 102,
|
||||||
if (storePath != expected)
|
"NAR hash mismatch in input '%s', expected '%s' but got '%s'",
|
||||||
throw Error(
|
originalInput.to_string(),
|
||||||
(unsigned int) 102,
|
getNarHash()->to_string(HashFormat::SRI, true),
|
||||||
"NAR hash mismatch in input '%s', expected '%s' but got '%s'",
|
originalInput.getNarHash()->to_string(HashFormat::SRI, true));
|
||||||
originalInput.to_string(),
|
|
||||||
store->printStorePath(storePath),
|
|
||||||
store->printStorePath(expected));
|
|
||||||
}
|
|
||||||
|
|
||||||
return storePath;
|
return storePath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue