You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@fmnxl (also cc @rockofox), and anyone interested: this issue keeps bugging me, probably for the same reason as you, nix-shell (so we can use zx in a "fully contained" way).
Given both #715 and #716 got closed without this being addressed, using "two shebangs" still results in a SyntaxError.
As I managed to find a different not-as-portable approach to overcome this limitation (which makes it a single shebang line), I'm sharing it here.
Afaict, it requires two things:
nix shell (and not nix-shell), i.e. the nix-command experimental feature turned on;
env with the -S flag:
-S, --split-string=S process and split S into separate arguments;
used to pass multiple arguments on shebang lines
in FreeBSD since 6.0 (November 2005); manually checked this version is also present in macOS (14.4 at least, but could not find a way to check since which macOS version).
If you can live with those two requirements, this is the shebang line:
@antonmedv I guess the reasoning behind this issue being a feature request was because it was possible for zx to be hackishly modified to support them (as implemented in #716).
@fmnxl@rockofox I just accidentally discovered that nix-shell parses nix-shell option hashbangs anywhere in the file.
This was discussed in NixOS/nix#2570 and finally documented in NixOS/nix#11202 (so the first reference to this in documentation appears in the 2.24 docs (last paragraph)).
Activity
feat: allow multiple lines of hashbangs (google#715)
jlbribeiro commentedon Aug 17, 2024
@fmnxl (also cc @rockofox), and anyone interested: this issue keeps bugging me, probably for the same reason as you,
nix-shell(so we can usezxin a "fully contained" way).Given both #715 and #716 got closed without this being addressed, using "two shebangs" still results in a
SyntaxError.As I managed to find a different not-as-portable approach to overcome this limitation (which makes it a single shebang line), I'm sharing it here.
Afaict, it requires two things:
nix shell(and notnix-shell), i.e. the nix-command experimental feature turned on;envwith the-Sflag:coreutils8.30 (July 2018);If you can live with those two requirements, this is the shebang line:
Please let me know if this works for you, and if you manage to find a way to simplify this.
(given the current files-without-extension temporary files behavior, I advise you to still use the
.mjsextension for now, unfortunately.)antonmedv commentedon Aug 17, 2024
Actually shbang supported via node. Zx not handles shbang.
antongolub commentedon Sep 11, 2024
Hmm... https://stackoverflow.com/questions/12910744/why-should-the-shebang-line-always-be-the-first-line
jlbribeiro commentedon Sep 13, 2024
@antonmedv I guess the reasoning behind this issue being a feature request was because it was possible for
zxto be hackishly modified to support them (as implemented in #716).@fmnxl @rockofox I just accidentally discovered that
nix-shellparsesnix-shelloption hashbangs anywhere in the file.This was discussed in NixOS/nix#2570 and finally documented in NixOS/nix#11202 (so the first reference to this in documentation appears in the 2.24 docs (last paragraph)).
As such, @antonmedv, I believe this issue can be closed because, as in the unofficial NixOS wiki Lua example, we can resort to JavaScript's block comments ("multi-line") to make this work with
nix-shell:antonmedv commentedon Sep 14, 2024
Should we add some notes about this behavior to documentation? A nix-guide of docs website?
@jlbribeiro maybe you can write a short .md file?
fix(cli): allow multiple lines of hashbangs (resolves google#715)