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

Make --arg work for undeclared arguments #1363

Closed
wants to merge 1 commit into from

Conversation

thufschmitt
Copy link
Member

Make the --arg and --argstr cli options work even if
the evaluated function doesn't explicitly declare this argument.

For example nix-instantiate --eval -E "{...}@args: args.foo" --arg foo 1 now apply the function with the argument { foo = 1 } (thus returns
1) instead of quietly ignoring the arg foo 1 option (and returning
<LAMBDA>):

nix-instantiate --eval -E "args: args.foo" --arg foo 1 now also returns 1.

I assumed that the actual behavior (--arg argument dropped when the
corresponding argument isn't explicitly declared) isn't intended and is a bug,
let me know if it isn't.

This should fix #1360

This commit makes the `--arg` and `--argstr` cli options work even if
the evaluated function doesn't explicitly declare this argument.

For example `nix-instantiate --eval -E "{...}@Args: args.foo" --arg foo
1` now apply the function with the argument `{ foo = 1 }` (thus returns
`1`) instead of quietly ignoring the `arg foo 1` option (and returning
`<LAMBDA>`)

Note that `nix-instantiate --eval -E "args: args.foo" --arg foo 1` now
also returns `1`.

Fixes NixOS#1360
@matthewbauer
Copy link
Member

Cool! I haven't been able to test it yet but that looks like it will fix the issue I was having.

One thing to be careful of is that this is changing behavior for all autoCallFunction not just with --arg. I wonder if some expressions rely on not all options getting set? Maybe we should verify it doesn't break nixpkgs evaluation. Even if it does though- this is arguably correct behavior so it can be fixed hopefully in nixpkgs.

@thufschmitt
Copy link
Member Author

I quickly grepped the nix repo, and it looks like autoCallFunction is only used to handle the --arg option.

Other than that, I've ran a couple of nix-build and nix-instantiatecommands in addition to nix testsuite. I don't know if there is a way to do more extensive testing.

@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--arg doesn't work for functions with ...
5 participants