mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Add --flat to nix add-to-store
This can be used to add flat hashes to the nix store.
This commit is contained in:
parent
11c97070f3
commit
1c55f16a16
1 changed files with 24 additions and 2 deletions
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue