Add --flat to nix add-to-store

This can be used to add flat hashes to the nix store.
This commit is contained in:
Matthew Bauer 2020-06-12 12:26:08 -05:00
parent 11c97070f3
commit 1c55f16a16

View file

@ -9,6 +9,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand
{
Path path;
std::optional<std::string> namePart;
FileIngestionMethod ingestionMethod = FileIngestionMethod::Recursive;
CmdAddToStore()
{
@ -21,6 +22,13 @@ struct CmdAddToStore : MixDryRun, StoreCommand
.labels = {"name"},
.handler = {&namePart},
});
addFlag({
.longName = "flat",
.shortName = 0,
.description = "use flat file ingestion",
.handler = {&ingestionMethod, FileIngestionMethod::Flat},
});
}
std::string description() override
@ -45,10 +53,24 @@ struct CmdAddToStore : MixDryRun, StoreCommand
auto narHash = hashString(htSHA256, *sink.s);
ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart));
ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, narHash, *namePart));
info.narHash = narHash;
info.narSize = sink.s->size();
info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
Hash hash;
switch (ingestionMethod) {
case FileIngestionMethod::Recursive: {
hash = info.narHash;
break;
}
case FileIngestionMethod::Flat: {
HashSink hsink(htSHA256);
readFile(path, hsink);
hash = hsink.finish().first;
break;
}
}
info.ca = makeFixedOutputCA(ingestionMethod, hash);
if (!dryRun) {
auto source = StringSource { *sink.s };