Backport shebang support for Nix CLI #295

Closed
opened 2024-05-10 03:00:12 +00:00 by srxl · 5 comments
Member

Nix 2.19 introduced support for using the nix CLI as a shebang interpreter (PR, documentation). It's not a super important feature, but it is a nice-to-have, IMO.

Describe the solution you'd like

As an example, I have a Fish script that has the following shebang:

#! /usr/bin/env nix
#! nix shell nixpkgs#fish --command fish

This would use the Fish shell to run the script's contents.

Describe alternatives you've considered

  • Just use nix-shell: My system's NIX_PATH is kinda broken at the moment and nix-shell doesn't work, but I have no reason to believe this wouldn't work otherwise.
  • Specify a devshell in the directory containing the script: Avoids the need for the Nix shebang, but maybe a bit overkill in some places.
## Is your feature request related to a problem? Please describe. Nix 2.19 introduced support for using the `nix` CLI as a shebang interpreter ([PR](https://github.com/NixOS/nix/pull/8327), [documentation](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#shebang-interpreter)). It's not a *super* important feature, but it is a nice-to-have, IMO. ## Describe the solution you'd like As an example, I have a Fish script that has the following shebang: ``` #! /usr/bin/env nix #! nix shell nixpkgs#fish --command fish ``` This would use the Fish shell to run the script's contents. ## Describe alternatives you've considered - Just use `nix-shell`: My system's NIX_PATH is kinda broken at the moment and `nix-shell` doesn't work, but I have no reason to believe this wouldn't work otherwise. - Specify a devshell in the directory containing the script: Avoids the need for the Nix shebang, but maybe a bit overkill in some places.
Owner

as I said over in the chat, I'm hesitant.

the goal is an admirable one, but the details look like kind of a nightmare and I'm not convinced this belongs in the nix executable at all. it seems like something that can and should be its own binary

looking at the upstream examples, they look exceptionally convoluted and dependent on fine details of lexing. every language design warning bell I have in me is going off. I strongly suspect that about two years from now, someone will think of a much simpler way to do this... at which time, it would be nice not to be locked into the complicated way forever for compatibility.

so, I lean strongly against this feature, but wanted to capture the reasoning for posterity. these will be easier decisions once we have more of the layering architecture in place; the looser things are coupled, the easier it is to leave our mistakes in the past.

as I said over in the chat, I'm hesitant. the goal is an admirable one, but the details look like kind of a nightmare and I'm not convinced this belongs in the nix executable at all. it seems like something that can and should be its own binary looking at the upstream examples, they look exceptionally convoluted and dependent on fine details of lexing. every language design warning bell I have in me is going off. I strongly suspect that about two years from now, someone will think of a much simpler way to do this... at which time, it would be nice not to be locked into the complicated way forever for compatibility. so, I lean strongly against this feature, but wanted to capture the reasoning for posterity. these will be easier decisions once we have more of the layering architecture in place; the looser things are coupled, the easier it is to leave our mistakes in the past.
Owner

um - I think this was clear in chat but in case it's not, I'm still very grateful that you raised this for discussion and filed an issue about it

um - I think this was clear in chat but in case it's not, I'm still very grateful that you raised this for discussion and filed an issue about it
Owner

also just so you know, the nix-shell shebang is spectacularly broken: https://github.com/NixOS/nix/pull/5088

(in addition, @puck found yet another bug in it, where if you use two spaces with #!nix-shell -p it causes a wicked parse error)

but it's unclear if we could fix the nix-shell shebang without regressing other things.

but also, there is nothing stopping someone writing a better one as an external tool and exploring that design space better (especially in re: how should this work for non-flakes equally) without committing lix to maintaining another questionable parser (we recall that the PR 8327 parser has some questionable syntax decisions that seem like footguns).

also just so you know, the `nix-shell` shebang is spectacularly broken: https://github.com/NixOS/nix/pull/5088 (*in addition*, @puck found yet another bug in it, where if you use two spaces with `#!nix-shell -p` it causes a wicked parse error) but it's unclear if we could fix the `nix-shell` shebang without regressing other things. but *also*, there is nothing stopping someone writing a better one as an external tool and exploring that design space better (especially in re: how should this work for non-flakes *equally*) without committing lix to maintaining another questionable parser (we recall that the PR 8327 parser has some questionable syntax decisions that seem like footguns).
Author
Member

Fair nuff. Unsure what the issue workflow tends to look like around these parts, so I'll leave it to yall to close or mark wontfix or stuff like that

Fair nuff. Unsure what the issue workflow tends to look like around these parts, so I'll leave it to yall to close or mark wontfix or stuff like that
Owner

Marking this wontfix, but per discussion on matrix, we are encouraging someone (srxl might have been nerd sniped) to prototype a better one in Rust with the intent that it might be included in Lix at some point, or it might just be a good piece of separate software!

Marking this wontfix, but per discussion on matrix, we are encouraging someone (srxl might have been nerd sniped) to prototype a better one in Rust with the intent that it might be included in Lix at some point, or it might just be a good piece of separate software!
jade closed this issue 2024-05-10 06:18:22 +00:00
jade added the
Status
wontfix
label 2024-05-10 06:18:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#295
No description provided.