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

nix run should not remove arguments after the first positional one #6933

Open
lheckemann opened this issue Aug 21, 2022 · 10 comments
Open

nix run should not remove arguments after the first positional one #6933

lheckemann opened this issue Aug 21, 2022 · 10 comments
Labels
bug idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. new-cli Relating to the "nix" command

Comments

@lheckemann
Copy link
Member

Describe the bug

nix run -f '<nixpkgs>' nix flake show --allow-import-from-derivation does not pass --allow-import-from-derivation to the child nix process as expected.

Workaround: nix run -f '<nixpkgs>' -- nix flake show --no-eval-cache (adding --).

nix-env --version output

Tested on both nix (Nix) 2.8.1 and nix (Nix) 2.10.0pre20220812_78bd377 (current lazy-trees).

@lheckemann lheckemann added the bug label Aug 21, 2022
@Kha
Copy link
Contributor

Kha commented Aug 21, 2022

@lheckemann
Copy link
Member Author

I'm fine with not supporting this use without --, but then IMHO it shouldn't pass any args that aren't preceded by -- on to the child. Allowing mixing Nix args and child process args is very confusing.

@fricklerhandwerk fricklerhandwerk added the new-cli Relating to the "nix" command label Sep 12, 2022
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Apr 28, 2023

Triaged in Nix team meeting:

  • @edolstra: this is consistent behavior that might not be intuitive
    • there is no special handling for positional parameters after the flake attribute
    • we could add that special handling
    • @fricklerhandwerk: what about the alternative of enforcing -- to separate the nested command?
      • @thufschmitt: probably wouldn't make the situation much better
  • needs discussion

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-04-28-nix-team-meeting-minutes-50/27698/1

@fricklerhandwerk
Copy link
Contributor

Discussed in Nix team meeting:

  • @roberth: most "higher order bash" commands that do exec separate the nested command line with --
    • @thufschmitt: ssh is a counterexample (that is hell to work with, admittedly)
  • @thufschmitt: plugin files handling is another precedence
    • @edolstra: yes, there is a special hack for that
  • @edolstra: we could have a special setting in the argument parsing
    • could also say that positional arguments must always be at the end
      • that would break a lot of stuff
    • @thufschmitt: a special case only for nix run would be less trouble
  • @roberth: two viable options (everything else is really verbose):
    1. separator (explicit)
    2. taking everything following the installable as arguments (implicit, "Docker style")
  • @thufschmitt: could also have --arg flags, would keep the parsing simple
    • @roberth: we should follow existing conventions and not try to be clever
  • decision: use everything after the installable parameter as the nested command line, but only for nix run and nix develop

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-05-05-nix-team-meeting-minutes-52/27893/1

@roberth roberth added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label May 22, 2023
@emilazy
Copy link
Member

emilazy commented Jun 18, 2023

As I just got frustrated by this for the nth time enough to open #8537 before seeing this issue with an approved label, I thought I should ask whether there are any particular nuances that will make implementing this difficult or if it'd be good for me to pick up for a PR?

@roberth
Copy link
Member

roberth commented Jun 22, 2023

Personally I haven't made changes to the argument parsing yet; perhaps @Ericson2314 or @edolstra have some insights into how to approach the implementation of this?

As far as the problem statement goes

use everything after the installable parameter as the nested command line, but only for nix run and nix develop

I think this captures it pretty well.

@emilazy
Copy link
Member

emilazy commented Jun 22, 2023

I'll take a crack at it once I pop a few yaks off the shaving stack (hacking.mdNixOS/nixpkgs#238531NixOS/nixpkgs#236656 (comment)NixOS/nixpkgs#238791...). I expect it shouldn't be too difficult as nix shell -c ... already works correctly.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/equivalent-of-nix-shell-run-with-nix-shell-or-nix-develop/34712/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. new-cli Relating to the "nix" command
Projects
None yet
Development

No branches or pull requests

6 participants