Curl to nix-shell

curl foobar.com/myfile.sh | sh and sh -c "$(curl foobar.com/myfile.sh)" are common idioms. I’m curious if there’s a way to do something like this with #!/usr/bin/env nix-shell scripts.

I’ve tried a few different permutations curl ... | sh, sh -c "$(curl ...)", curl ... | nix-shell, curl ... | /usr/bin/env, etc but without any success. Is there anything better than just curl script.py && chmod +x script.py && ./script.py && rm script.py?

If you pipe into an interpreter, you need to specify the correct one from the start, the shebang won’t be interpreted.

So curl … | nix-shell -p python3 -c python should do.

And to be honest… Even though the following is true, it really shouldn’t…

  1. Download
  2. Review
  3. Execute

should be prefered, even if the instruction tell you to run curl|sh

1 Like

Thanks, I’ll try that out!

Agreed, always. But for the sake of convenience it can be handy from trusted sources.