The --arg option does not seem to pass args to a function when it isn't explicitly listed as an argument. This breaks when you use "ellipsis" for example in impure.nix:
see NixOS/nixpkgs#25215 for more discussion
This is by design. We only want to pass arguments that a function explicitly expects.
I must admit I don't really understand the reason for this. Is this a
security feature to prevent accidentally passing unwanted arguments or
is there another reason?
@edolstra I guess isn't the function asking for unexpected args when it has the .../ellipsis? I guess the issue is that it only comes into play when you are using --arg because you can pass other args in when it's just a normal function call.
Anyway, if it is by design, can we get it documented? All I see on with is here in the manual:
http://nixos.org/nix/manual/#idm140737318021024
But I definitely could have missed it.
@edolstra is that a good design though? Certainly functions without ellipses should not accept unlisted arguments but the whole point of ellipses is that the set of parameter is open-ended. At the very least it should be an error to pass an improper argument.
@edolstra I'm also not convinced that this was the right decision. There's a usecase where a function can be "built" dynamically in Nix like this: (args @ { ... }: builtins.getAttr "a" args). Allowing dynamically built functions like these to accept arguments from --arg and --argstr would be really useful. What value are Nix users getting by this not being allowed?
Is there a use-case where silently dropping unsupported args makes sense? It seems to me like it would be preferable to be explicit about these types of things. The person who writes the nix code is still able to decide whenever arbitrary arguments are allowed or not with the ... syntax.
Right now it's problematic because it's not possible to detect when an argument is unsupported. This can happen if the key is mistyped and a default value is available in the function attributes for example.
I found where the logic resides, it's embedded deep into libexpr: https://github.com/NixOS/nix/blob/4ae6e849015fb269414c1544e815aba75085cf7b/src/libexpr/eval.cc#L1205-L1218
Most helpful comment
@edolstra is that a good design though? Certainly functions without ellipses should not accept unlisted arguments but the whole point of ellipses is that the set of parameter is open-ended. At the very least it should be an error to pass an improper argument.