nix-build / nix-instantiate will silently ignore unknown arguments being passed with --arg #865

Closed
opened 2025-06-21 22:37:47 +00:00 by raito · 6 comments
Owner

Describe the bug

Imagine you have: { }: true as a file.

You do: nix-build --arg something true on that file and you expect to get an error because you are passing an argument that doesn't exist.

But, you do not.

Steps To Reproduce

  1. { }: true in default.nix
  2. nix-instantiate --arg something true --eval -f default.nix
  3. See true being returned

Expected behavior

nix-repl> ({ }: true) { a = 5; }
error:
       … from call site
         at «string»:1:1:
            1| ({ }: true) { a = 5; }
             | ^

       error: function 'anonymous lambda' called with unexpected argument 'a'
       at «string»:1:2:
            1| ({ }: true) { a = 5; }
             |  ^

nix --version output

Lix 2.94.0-dev.

Happens also in CppNix.

Additional context

This caused a silent bug in the functional1 test suite with non-UTF8 inodes, I passed the wrong argument nonUtf8Inode instead of nonUtf8Inodes and generated NO non-UTF8 inodes.

Tough luck.

## Describe the bug Imagine you have: `{ }: true` as a file. You do: `nix-build --arg something true` on that file and you expect to get an error because you are passing an argument that doesn't exist. But, you do not. ## Steps To Reproduce 1. `{ }: true` in `default.nix` 2. `nix-instantiate --arg something true --eval -f default.nix` 3. See `true` being returned ## Expected behavior ``` nix-repl> ({ }: true) { a = 5; } error: … from call site at «string»:1:1: 1| ({ }: true) { a = 5; } | ^ error: function 'anonymous lambda' called with unexpected argument 'a' at «string»:1:2: 1| ({ }: true) { a = 5; } | ^ ``` ## `nix --version` output Lix 2.94.0-dev. Happens also in CppNix. ## Additional context This caused a silent bug in the functional1 test suite with non-UTF8 inodes, I passed the wrong argument `nonUtf8Inode` instead of `nonUtf8Inodes` and generated _NO_ non-UTF8 inodes. Tough luck.
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/3407 ("libstore/binary-cache: fix catching JSON exceptions")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/3407", "number": 3407, "kind": "commit message"}], "cl_meta": {"3407": {"change_title": "libstore/binary-cache: fix catching JSON exceptions"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/3407](https://gerrit.lix.systems/c/lix/+/3407) ("libstore/binary-cache: fix catching JSON exceptions")
Owner

This is because of autocall, which is really jank. I think if we wanted to fix this, we could track what was autocalled and what with and then generate a diagnostic if an input was never used. It's plausible that we can't make this a hard error as autocall is at any level: lix tries to call every function it runs into with the given arg in a kind of sketchy way, so it's very possible that a lot of people are relying on this unfortunate design.

This is because of autocall, which is really jank. I think if we wanted to fix this, we could track what was autocalled and what with and then generate a diagnostic if an input was never used. It's plausible that we can't make this a hard error as autocall is at any level: lix tries to call every function it runs into with the given arg in a kind of sketchy way, so it's very possible that a lot of people are relying on this unfortunate design.
Member

That doesn't sound like it is unreasonable to emit a diagnostic for in nearly every case, unless people have come up not just relying on this behavior by accident, but as intentional design (ie, they would get spammed with warnings from that).

There is however the question, do we want people to rely on this design? Can we come up with a timeline along which we can eventually turn that diagnostic into a hard error, even if it is going to sometimes painful as we only know it at the far end of eval that we have not consumed all the args.

That doesn't sound like it is unreasonable to emit a diagnostic for in nearly every case, unless people have come up not just relying on this behavior by accident, but as intentional design (ie, they would get spammed with warnings from that). There is however the question, do we want people to rely on this design? Can we come up with a timeline along which we can eventually turn that diagnostic into a hard error, even if it is going to sometimes painful as we only know it at the far end of eval that we have not consumed all the args.
Owner

I don't think this is the first bug report about autocall either, pennae thinks it's evil and it's been on their shit list forever. The last one I'm thinking of is relating to --arg and --expr not liking each other iirc

I don't think this is the first bug report about autocall either, pennae thinks it's evil and it's been on their shit list forever. The last one I'm thinking of is relating to --arg and --expr not liking each other iirc
Owner

#263 pawhaps

https://git.lix.systems/lix-project/lix/issues/263 pawhaps
Owner

lol this is a duplicate #775 (comment)

lol this is a duplicate https://git.lix.systems/lix-project/lix/issues/775#issue-13160
jade closed this issue 2025-06-22 08:35:31 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
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#865
No description provided.