Caching NAR hashes instead of store paths makes the cache more general, because we can always compute the store path from the NAR hash, but not the other way around. This is useful for lazy trees, where we want to compute the NAR hash of an input with caching.
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include "nix/store/store-api.hh"
|
|
#include "nix/expr/eval.hh"
|
|
#include "nix/util/mounted-source-accessor.hh"
|
|
#include "nix/fetchers/fetch-to-store.hh"
|
|
|
|
namespace nix {
|
|
|
|
SourcePath EvalState::rootPath(CanonPath path)
|
|
{
|
|
return {rootFS, std::move(path)};
|
|
}
|
|
|
|
SourcePath EvalState::rootPath(PathView path)
|
|
{
|
|
return {rootFS, CanonPath(absPath(path))};
|
|
}
|
|
|
|
SourcePath EvalState::storePath(const StorePath & path)
|
|
{
|
|
return {rootFS, CanonPath{store->printStorePath(path)}};
|
|
}
|
|
|
|
StorePath
|
|
EvalState::mountInput(fetchers::Input & input, const fetchers::Input & originalInput, ref<SourceAccessor> accessor)
|
|
{
|
|
auto [storePath, narHash] = fetchToStore2(fetchSettings, *store, accessor, FetchMode::Copy, input.getName());
|
|
|
|
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
|
|
|
|
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
|
|
|
|
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
|
|
|
if (originalInput.getNarHash() && narHash != *originalInput.getNarHash())
|
|
throw Error(
|
|
(unsigned int) 102,
|
|
"NAR hash mismatch in input '%s', expected '%s' but got '%s'",
|
|
originalInput.to_string(),
|
|
narHash.to_string(HashFormat::SRI, true),
|
|
originalInput.getNarHash()->to_string(HashFormat::SRI, true));
|
|
|
|
return storePath;
|
|
}
|
|
|
|
} // namespace nix
|