Nix-shell shebang: run any script with arbitrary packages, self-contained
nixos.wiki
nixos.wiki
Scriptisto: "Shebang interpreter" that enables writing scripts in compiled langs - https://news.ycombinator.com/item?id=39272890 - Feb 2024 (14 comments)
There's nothing wrong with the current submission in principle, but it's best not to post follow-up links [1] as top-level submissions—rather, they should be comments in the original thread, as you did here: https://news.ycombinator.com/item?id=39292955.
The reason is that frontpage slots are the scarcest resource HN has [2], so we want to keep them as uncorrelated with each other as possible. When they aren't, readers soon start to complain about the repetition [3].
Not a criticism! Just want to get the word out.
[1] https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
[2] https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
[3] https://hn.algolia.com/?dateRange=all&page=0&prefix=false&so...
Regarding your observation, the bottom of the wiki page references a project that addresses the issue with the slowness of nix-shell: https://github.com/xzfc/cached-nix-shell
command_not_found_handle() {
eval "$(command-not-found $1 2>&1 | sed -n 3p) --run '$@'"
}
Now you have any command available, no matter if installed or not.I haven't used this for anything complex, so it may need a little bit of tweaking.
[0] - https://jackson.dev/post/a-portable-nix-shell-shebang/
I wasn't aware of this, it's nice to know.
Works for scripts that need to list/signal other processes.