1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 15:31:47 +02:00

GitArchiveInputScheme: Bring back the narHash attribute

This is needed to verify that the source tree served by GitHub hasn't
changed compared to the lock file. Computing the narHash for a nixpkgs
source tree only takes ~0.6s and it's cached. So the cost is fairly
negligible compared to the download time.
This commit is contained in:
Eelco Dolstra 2022-11-03 14:23:24 +01:00
parent 8342317d4d
commit 4072024d79
3 changed files with 35 additions and 0 deletions

View file

@ -220,6 +220,25 @@ struct GitArchiveInputScheme : InputScheme
auto accessor = makeZipInputAccessor(CanonPath(store->toRealPath(storePath))); auto accessor = makeZipInputAccessor(CanonPath(store->toRealPath(storePath)));
/* Compute the NAR hash of the contents of the zip file. This
is checked against the NAR hash in the lock file in
Input::checkLocks(). */
auto key = fmt("zip-nar-hash-%s", store->toRealPath(storePath.to_string()));
auto cache = getCache();
auto narHash = [&]() {
if (auto narHashS = cache->queryFact(key)) {
return Hash::parseSRI(*narHashS);
} else {
auto narHash = accessor->hashPath(CanonPath::root);
cache->upsertFact(key, narHash.to_string(SRI, true));
return narHash;
}
}();
input2.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true));
auto lastModified = accessor->getLastModified(); auto lastModified = accessor->getLastModified();
assert(lastModified); assert(lastModified);
input2.attrs.insert_or_assign("lastModified", uint64_t(*lastModified)); input2.attrs.insert_or_assign("lastModified", uint64_t(*lastModified));

View file

@ -87,6 +87,16 @@ void InputAccessor::dumpPath(
dump(path); dump(path);
} }
Hash InputAccessor::hashPath(
const CanonPath & path,
PathFilter & filter,
HashType ht)
{
HashSink sink(ht);
dumpPath(path, sink, filter);
return sink.finish().first;
}
StorePath InputAccessor::fetchToStore( StorePath InputAccessor::fetchToStore(
ref<Store> store, ref<Store> store,
const CanonPath & path, const CanonPath & path,

View file

@ -5,6 +5,7 @@
#include "archive.hh" #include "archive.hh"
#include "canon-path.hh" #include "canon-path.hh"
#include "repair-flag.hh" #include "repair-flag.hh"
#include "hash.hh"
namespace nix { namespace nix {
@ -57,6 +58,11 @@ struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
Sink & sink, Sink & sink,
PathFilter & filter = defaultPathFilter); PathFilter & filter = defaultPathFilter);
Hash hashPath(
const CanonPath & path,
PathFilter & filter = defaultPathFilter,
HashType ht = htSHA256);
StorePath fetchToStore( StorePath fetchToStore(
ref<Store> store, ref<Store> store,
const CanonPath & path, const CanonPath & path,