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-shell in second #! line only accepts double quotes for package expressions #2356

Closed
cumber opened this issue Aug 15, 2018 · 8 comments · Fixed by #8470
Closed

nix-shell in second #! line only accepts double quotes for package expressions #2356

cumber opened this issue Aug 15, 2018 · 8 comments · Fixed by #8470

Comments

@cumber
Copy link

cumber commented Aug 15, 2018

This works:

#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p "ghc.withPackages (ps: [ ps.HTTP ])"

This does not:

#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p 'ghc.withPackages (ps: [ ps.HTTP ])'

Running a script with the above lines produces: error: syntax error, unexpected $undefined, at (string):1:94

The syntax of the extra #! nix-shell lines looks like we're writing shell command syntax, so people think that bash-like (or at least sh-like) quoting rules would apply.

Ideally single quotes would work as well as double quotes, but either way the manual (https://nixos.org/nix/manual/#ssec-nix-shell-shebang) should at talk about how to properly quote complex arguments; currently none of the examples need quoting, and there is no mention of whether any kind of quoting is supported or not (which leads to the guess that bash-like quotes would be supported from the similar syntax).

@bhipple
Copy link
Contributor

bhipple commented Aug 27, 2018

This actually just bit me a few days ago while trying to use a python.withPackages. I eventually figured out the right syntax is as you have written above but a quick mention in the manual or a complex example would've been nice!

@toonn
Copy link
Contributor

toonn commented Nov 21, 2018

This is a regression. I got the exact same error on a haskell script I've used succesfully before.

@domenkozar
Copy link
Member

Needs single quote handling in

@AleXoundOS
Copy link

AleXoundOS commented Jan 16, 2021

Not only package expression is affected, but any expression in single quotes. The problem is that inner double quotes need to be escaped:

#! /usr/bin/env nix-shell
#! nix-shell -E "with import <nixpkgs> {}; runCommand \"dummy\" {} \"\""

@stale
Copy link

stale bot commented Jul 16, 2021

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

@stale stale bot added the stale label Jul 16, 2021
@AleXoundOS
Copy link

For those, who needs long/complex nix expression in shebang in a single file, I've found a semi-solution with the help of /usr/bin/env -S, what avoids this quotes issue as well.

@stale stale bot removed the stale label Jul 17, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

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

@ncfavier
Copy link
Member

ncfavier commented Jun 7, 2023

#8470

@stale stale bot removed the stale label Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants