aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2020-06-09 01:23:37 -0500
committerMatthew Bauer <mjbauer95@gmail.com>2020-06-09 01:23:37 -0500
commit762273f1fd48b2b2f2bbedca65abfd4c07b5af05 (patch)
tree2a7c38e5af4cdd9dfc3302a2c0873f51b59470da
parentd558fb98f6f8ce32e5c08a36d798441f1b941ba8 (diff)
Allow empty hash in derivations
follow up of https://github.com/NixOS/nix/pull/3544 This allows hash="" so that it can be used for debugging purposes. For instance, this gives you an error message like: warning: found empty hash, assuming you wanted 'sha256:0000000000000000000000000000000000000000000000000000' hash mismatch in fixed-output derivation '/nix/store/asx6qw1r1xk6iak6y6jph4n58h4hdmbm-nix': wanted: sha256:0000000000000000000000000000000000000000000000000000 got: sha256:0fpfhipl9v1mfzw2ffmxiyyzqwlkvww22bh9wcy4qrfslb4jm429
-rw-r--r--src/libexpr/primops.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index d458ab272..de04fd2be 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -719,7 +719,13 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName);
HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo);
- Hash h(*outputHash, ht);
+
+ Hash h;
+ if (outputHash->empty()) {
+ h = Hash(ht);
+ printError("warning: found empty hash, assuming you wanted '%s'", h.to_string());
+ } else
+ h = Hash(*outputHash, ht);
auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName);
if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath);