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 multi-line shebang is not handled by just #2024

Open
oux opened this issue May 7, 2024 · 1 comment
Open

nix multi-line shebang is not handled by just #2024

oux opened this issue May 7, 2024 · 1 comment

Comments

@oux
Copy link

oux commented May 7, 2024

Environment:

  • nix 2.20.1 or later
  • just 1.25.2

justfile:

hello:
  #!/usr/bin/env nix
  #! nix shell  nixpkgs#hello nixpkgs#cowsay --command bash
  hello | cowsay

Error:
image

Same shebang on a simple shell script file:
image

Nix shebang documentation:
https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#shebang-interpreter

@casey
Copy link
Owner

casey commented May 22, 2024

I think the reason this doesn't work is that when just extracts the body of a shebang recipe into a file to execute, just places the shabang line first, and then inserts blank lines before inserting the contents of the recipe, so that line numbers in error messages correspond to line numbers of the recipe.

So the way to fix this is to see if the next line is a shebang and put it at the top of the file.

So for example, this:

hello:
  #!/usr/bin/env nix
  #! nix shell  nixpkgs#hello nixpkgs#cowsay --command bash
  hello | cowsay

Is currently translated to this:

#!/usr/bin/env nix

#! nix shell  nixpkgs#hello nixpkgs#cowsay --command bash
hello | cowsay

When it should be translated to this:

#!/usr/bin/env nix
#! nix shell  nixpkgs#hello nixpkgs#cowsay --command bash

hello | cowsay

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

No branches or pull requests

2 participants