diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-08-07 14:44:47 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-08-07 14:44:47 +0000 |
commit | 39ae9a3d4a96ca4a5460c1b6264e77e71c3aad5f (patch) | |
tree | 1f91c2016b03146f35b02b4c575d708190719a03 /src/nix/add-to-store.cc | |
parent | 3537670fefab6c65b4b87837112d64931dcda4cf (diff) | |
parent | 61464478427c4106ce20c1e61bfd5f53f3f49f37 (diff) |
Merge remote-tracking branch 'upstream/master' into fix-and-ci-static-builds
Diffstat (limited to 'src/nix/add-to-store.cc')
-rw-r--r-- | src/nix/add-to-store.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index b3eec0146..eaec63349 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -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 = "add flat file to the Nix store", + .handler = {&ingestionMethod, FileIngestionMethod::Flat}, + }); } std::string description() override @@ -45,12 +53,19 @@ struct CmdAddToStore : MixDryRun, StoreCommand auto narHash = hashString(htSHA256, *sink.s); - ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart)); + Hash hash = narHash; + if (ingestionMethod == FileIngestionMethod::Flat) { + HashSink hsink(htSHA256); + readFile(path, hsink); + hash = hsink.finish().first; + } + + ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, hash, *namePart)); info.narHash = narHash; info.narSize = sink.s->size(); info.ca = std::optional { FixedOutputHash { - .method = FileIngestionMethod::Recursive, - .hash = *info.narHash, + .method = ingestionMethod, + .hash = hash, } }; if (!dryRun) { |