[Nix#9700] Bad error message for nix build of a string #74

Open
opened 2024-03-16 06:44:46 +00:00 by lix-bot · 0 comments
Member

Upstream-Issue: NixOS/nix#9700

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.

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/9700 **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 :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).
lix-bot added the
ux
bug
imported
labels 2024-03-16 06:44:46 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#74
No description provided.