Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

trofi
Copy link
Contributor

@trofi trofi commented Dec 25, 2024

Motivation

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 'lib' contains an illegal reference specifier 'man', expected store path or output name (one of [debug, dev, doc, lib, out])

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@wolfgangwalther
Copy link

Would it be possible to also print the file that contains that reference?

@wolfgangwalther
Copy link

As for the postgresql_14 example itself: This could be a nix bug in the first place - see efforts in NixOS/nixpkgs#368091 to track this down.

@trofi
Copy link
Contributor Author

trofi commented Dec 30, 2024

Would it be possible to also print the file that contains that reference?

Commit message shows the new error message as:

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

Do you mean something else than '/nix/store/bxp6g57limvwiga61vdlyvhy7i8rp6wd-postgresql-14.15.drv' derivation file?

@wolfgangwalther
Copy link

Do you mean something else than '/nix/store/bxp6g57limvwiga61vdlyvhy7i8rp6wd-postgresql-14.15.drv' derivation file?

Yeah, I mean the file inside the output. So in this case nix finds a file inside the lib output that has a reference to the man output, right? But which file inside ...-lib/* contains this reference?

@trofi
Copy link
Contributor Author

trofi commented Dec 30, 2024

As for the postgresql_14 example itself: This could be a nix bug in the first place - see efforts in NixOS/nixpkgs#368091 to track this down.

Yes, I believe it's a nix bug. But I would say fixing it out of scope of this PR (I did not start debugging it yet).

@wolfgangwalther
Copy link

But I would say fixing it out of scope of this PR (I did not start debugging it yet).

Yes, 100%.

@wolfgangwalther
Copy link

Yeah, I mean the file inside the output. So in this case nix finds a file inside the lib output that has a reference to the man output, right? But which file inside ...-lib/* contains this reference?

Maybe I misunderstand the error, though...

@trofi
Copy link
Contributor Author

trofi commented Dec 30, 2024

Do you mean something else than '/nix/store/bxp6g57limvwiga61vdlyvhy7i8rp6wd-postgresql-14.15.drv' derivation file?

Yeah, I mean the file inside the output. So in this case nix finds a file inside the lib output that has a reference to the man output, right? But which file inside ...-lib/* contains this reference?

No, I think nix believes that man output is not present in those derivation at all:

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

Note how man is not in the list of expected identifiers. The specific nix code is:

throw BuildError("derivation contains an illegal reference specifier '%s'", i);

                for (auto & i : *value) {
                    if (worker.store.isStorePath(i))
                        spec.insert(worker.store.parseStorePath(i));
                    else if (auto output = get(outputs, i))
                        spec.insert(output->path);
                    else
                        throw BuildError("derivation contains an illegal reference specifier '%s'", i);
                }

I think auto output = get(outputs, i) is expected to return something here, but it does not. I would expect some ortdering problem where the map is corrupted, or missing prerequisite problem when only a subset of outputs fetched from the cache.

@wolfgangwalther
Copy link

No, I think nix believes that man output is not present in those derivation at all:

Ah, ok. Now I got it.

Could we change the error message as follows then?

-error: derivation '/nix/store/bxp6g57limvwiga61vdlyvhy7i8rp6wd-postgresql-14.15.drv' output 'lib' contains an illegal reference specifier 'man', expected store path or output name (one of [debug, dev, doc, lib, out])
+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])

(is that correct?)

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])
@trofi trofi force-pushed the local-derivation-goal-better-reference-bug branch from 4afd6f5 to ec46a7e Compare December 30, 2024 10:30
@trofi
Copy link
Contributor Author

trofi commented Dec 30, 2024

Yeah, that matches my understanding. Updated the PR with your suggestion as:

--- a/src/libstore/unix/build/local-derivation-goal.cc
+++ b/src/libstore/unix/build/local-derivation-goal.cc
@@ -2936,3 +2936,3 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo
                         }
-                        throw BuildError("derivation '%s' output '%s' contains an illegal reference specifier '%s',"
+                        throw BuildError("derivation '%s' output check for '%s' contains an illegal reference specifier '%s',"
                             " expected store path or output name (one of [%s])",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants