diff --git a/doc/manual/rl-next/fod-failure-includes-url.md b/doc/manual/rl-next/fod-failure-includes-url.md new file mode 100644 index 000000000..43179aa52 --- /dev/null +++ b/doc/manual/rl-next/fod-failure-includes-url.md @@ -0,0 +1,16 @@ +--- +synopsis: "Hash mismatch diagnostics for fixed-output derivations include the URL" +cls: [1536] +credits: [jade] +category: Improvements +--- + +Now, when building fixed-output derivations, Lix will guess the URL that was used in the derivation using the `url` or `urls` properties in the derivation environment. +This is a layering violation but making these diagnostics tractable when there are multiple instances of the `AAAA` hash is too significant of an improvement to pass it up. + +``` +error: hash mismatch in fixed-output derivation '/nix/store/sjfw324j4533lwnpmr5z4icpb85r63ai-x1.drv': + likely URL: https://meow.puppy.forge/puppy.tar.gz + specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= + got: sha256-a1Qvp3FOOkWpL9kFHgugU1ok5UtRPSu+NwCZKbbaEro= +``` diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 968f669ec..1dd2ad8aa 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -2546,9 +2546,12 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs() /* Throw an error after registering the path as valid. */ worker.hashMismatch = true; + // XXX: shameless layering violation hack that makes the hash mismatch error at least not utterly worthless + auto guessedUrl = getOr(drv->env, "urls", getOr(drv->env, "url", "(unknown)")); delayedException = std::make_exception_ptr( - BuildError("hash mismatch in fixed-output derivation '%s':\n specified: %s\n got: %s", + BuildError("hash mismatch in fixed-output derivation '%s':\n likely URL: %s\n specified: %s\n got: %s", worker.store.printStorePath(drvPath), + guessedUrl, wanted.to_string(SRI, true), got.to_string(SRI, true))); } diff --git a/tests/functional/build.sh b/tests/functional/build.sh index 95a20dc6a..a540cf8fd 100644 --- a/tests/functional/build.sh +++ b/tests/functional/build.sh @@ -142,6 +142,8 @@ test "$(<<<"$out" grep -E '^error:' | wc -l)" = 2 <<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x1\\.drv'" <<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x3\\.drv'" <<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x2\\.drv'" +<<<"$out" grepQuiet -E "likely URL: https://meow.puppy.forge/puppy.tar.gz" +<<<"$out" grepQuiet -vE "likely URL: https://kitty.forge/cat.tar.gz" <<<"$out" grepQuiet -E "error: build of '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out' failed" out="$(nix build -f fod-failing.nix -L x1 x2 x3 --keep-going 2>&1)" && status=0 || status=$? @@ -151,6 +153,9 @@ test "$(<<<"$out" grep -E '^error:' | wc -l)" = 4 <<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x1\\.drv'" <<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x3\\.drv'" <<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x2\\.drv'" +<<<"$out" grepQuiet -E "likely URL: https://meow.puppy.forge/puppy.tar.gz" +<<<"$out" grepQuiet -E "likely URL: https://kitty.forge/cat.tar.gz" +<<<"$out" grepQuiet -E "likely URL: \(unknown\)" <<<"$out" grepQuiet -E "error: build of '.*-x[1-3]\\.drv\\^out', '.*-x[1-3]\\.drv\\^out', '.*-x[1-3]\\.drv\\^out' failed" out="$(nix build -f fod-failing.nix -L x4 2>&1)" && status=0 || status=$? diff --git a/tests/functional/fod-failing.nix b/tests/functional/fod-failing.nix index 37c04fe12..b63fbd900 100644 --- a/tests/functional/fod-failing.nix +++ b/tests/functional/fod-failing.nix @@ -6,6 +6,7 @@ rec { '' echo $name > $out ''; + url = "https://meow.puppy.forge/puppy.tar.gz"; outputHashMode = "recursive"; outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; }; @@ -15,6 +16,7 @@ rec { '' echo $name > $out ''; + urls = "https://kitty.forge/cat.tar.gz"; outputHashMode = "recursive"; outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; };