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

Bad error message for nix build of a string #9700

Open
lf- opened this issue Jan 6, 2024 · 3 comments
Open

Bad error message for nix build of a string #9700

lf- opened this issue Jan 6, 2024 · 3 comments
Labels
bug error-messages Confusing messages and better diagnostics new-cli Relating to the "nix" command

Comments

@lf-
Copy link
Member

lf- commented Jan 6, 2024

Describe the bug

Invoking nix build against a string containing a store path causes sadness: it does not build anything and returns an error seemingly nothing to do with the actual problem.

Steps To Reproduce

Put this in a file:

let
  Caddyfile-formatted = builtins.derivation { system = "x86_64-linux"; name = "test"; builder = "/bin/sh"; args = ["-c" "> $out" ]; };
in
"${Caddyfile-formatted}/Caddyfile"

nix build -f ./bug.nix

error:
       … while evaluating the attribute ''

         at «none»:0: (source not available)

       error: string '/nix/store/nfb1lb8dd7wxn0g9cccq2a9zf8dk219a-test/Caddyfile' has context with the output 'out' from derivation '/nix/store/qvryn0lpyyizpqn55i9fdklb5l3d97b6-test.drv', but the string is not the right placeholder for this derivation 
output. It should be '/nix/store/nfb1lb8dd7wxn0g9cccq2a9zf8dk219a-test'

Expected behavior

I expected the error message to be less bad, for example, what nix-build bug.nix does:

error: expression does not evaluate to a derivation (or a set or list of those)

although I will note that that error is also terrible, but for different reasons: it doesn't do the thing you want. The case I had here is that I needed to nix eval some string, and then build the derivation from it. I took the store path in the string and gave it to nix build, but it couldn't identify the derivation file necessary to build it.

nix-env --version output

nix-env (Nix) 2.18.1

Additional context

This occurred in practice while trying to get something out of a NixOS config under environment.etc.something.source.

Priorities

Add 👍 to issues you find important.

@lf- lf- added the bug label Jan 6, 2024
@roberth
Copy link
Member

roberth commented Jan 8, 2024

nix eval some string, and then build the derivation from it.

I've previously proposed to add this as a feature

The error should then also be improved to point out that this feature exists.
I think the new behavior should only be enabled when explicitly requested; otherwise things get very ambiguous when the wrong behavior is activated by mistake.

@roberth roberth added new-cli Relating to the "nix" command error-messages Confusing messages and better diagnostics labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error-messages Confusing messages and better diagnostics new-cli Relating to the "nix" command
Projects
None yet
Development

No branches or pull requests

3 participants