local-derivation-goal: improve "illegal reference" error

Before the change "illegal reference" was hard to interpret as it did
not mention what derivation actually hits it.

Today's `nixpkgs` example:

Before the change:

    $ nix build --no-link -f. postgresql_14
    ...
    error: derivation contains an illegal reference specifier 'man'

After the change:

    $ nix build --no-link -f. postgresql_14
    ...
    error: derivation '/nix/store/bxp6g57limvwiga61vdlyvhy7i8rp6wd-postgresql-14.15.drv' output check for 'lib' contains an illegal reference specifier 'man', expected store path or output name (one of [debug, dev, doc, lib, out])

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Maximilian Bosch <maximilian@mbosch.me>

(cherry picked from commit ec46a7e4dea8c568677d3d98588810bcd178f048)
Change-Id: I36e3e951c282123e780a920d5bef59de74de9fe0
This commit is contained in:
Sergei Trofimovich
2025-01-20 15:05:50 +01:00
committed by Maximilian Bosch
parent 35e4f5f455
commit 108c051fd8
3 changed files with 28 additions and 2 deletions
+18 -2
View File
@@ -2516,8 +2516,24 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo
spec.insert(output->path);
else if (auto storePath = get(alreadyRegisteredOutputs, i))
spec.insert(*storePath);
else
throw BuildError("derivation contains an illegal reference specifier '%s'", i);
else {
std::string outputsListing = concatMapStringsSep(
", ",
newlyBuiltOutputs,
[](auto & o) { return o.first; }
);
if (!alreadyRegisteredOutputs.empty()) {
outputsListing.append(outputsListing.empty() ? "" : ", ");
outputsListing.append(concatMapStringsSep(
", ",
alreadyRegisteredOutputs,
[](auto & o) { return o.first; })
);
}
throw BuildError("derivation '%s' output check for '%s' contains an illegal reference specifier '%s',"
" expected store path or output name (one of [%s])",
worker.store.printStorePath(drvPath), outputName, i, outputsListing);
}
}
auto used = recursive
+6
View File
@@ -74,4 +74,10 @@ rec {
buildCommand = ''echo ${dep} > "''${outputs[out]}"'';
};
test12 = makeTest 12 {
builder = builtins.toFile "builder.sh" "mkdir $out $lib";
outputs = ["out" "lib"];
disallowedReferences = ["dev"];
};
}
+4
View File
@@ -51,3 +51,7 @@ if isDaemonNewer 2.12pre20230103; then
test11=$(nix-build -o $RESULT check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]]
fi
# test12 should fail (syntactically invalid).
expectStderr 1 nix-build -vvv -o "$RESULT" check-refs.nix -A test12 >"$TEST_ROOT/test12.stderr"
grepQuiet -F "output check for 'lib' contains an illegal reference specifier 'dev', expected store path or output name (one of [lib, out])" < "$TEST_ROOT/test12.stderr"