Skip to content

Commit

Permalink
Merge pull request NixOS#9809 from obsidiansystems/nix-store-add-algo
Browse files Browse the repository at this point in the history
Add missing `--hash-algo` flag to `nix store add`
  • Loading branch information
Ericson2314 authored Jan 20, 2024
2 parents 382fa51 + 356352c commit 9b896bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions doc/manual/rl-next/nix-store-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
synopsis: Give `nix store add` a `--hash-algo` flag
prs: 9809
---

Adds a missing feature that was present in the old CLI, and matches our
plans to have similar flags for `nix hash convert` and `hash hash path`.
7 changes: 5 additions & 2 deletions src/nix/add-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand
Path path;
std::optional<std::string> namePart;
ContentAddressMethod caMethod = FileIngestionMethod::Recursive;
HashAlgorithm hashAlgo = HashAlgorithm::SHA256;

CmdAddToStore()
{
Expand Down Expand Up @@ -51,6 +52,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand
this->caMethod = parseIngestionMethod(s);
}},
});

addFlag(Flag::mkHashAlgoFlag("hash-algo", &hashAlgo));
}

void run(ref<Store> store) override
Expand All @@ -63,9 +66,9 @@ struct CmdAddToStore : MixDryRun, StoreCommand

auto storePath = dryRun
? store->computeStorePath(
*namePart, accessor, path2, caMethod, HashAlgorithm::SHA256, {}).first
*namePart, accessor, path2, caMethod, hashAlgo, {}).first
: store->addToStoreSlow(
*namePart, accessor, path2, caMethod, HashAlgorithm::SHA256, {}).path;
*namePart, accessor, path2, caMethod, hashAlgo, {}).path;

logger->cout("%s", store->printStorePath(storePath));
}
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ clearStore
path3=$(nix store add-path ./dummy)
[[ "$path1" == "$path2" ]]
[[ "$path1" == "$path3" ]]
path4=$(nix store add --mode nar --hash-algo sha1 ./dummy)
)
(
path1=$(nix store add --mode flat ./dummy)
path2=$(nix store add-file ./dummy)
[[ "$path1" == "$path2" ]]
path4=$(nix store add --mode flat --hash-algo sha1 ./dummy)
)

0 comments on commit 9b896bf

Please sign in to comment.