Ah yes, the classic cases of the right way, the wrong way, and the Nix way. ![]()
I always write my scripts with a /usr/bin/env shebang as a base, nix will patch it for me, when actually building with nix, though not all of my scripts are used through nix exclusively. Be it because I share them with co workers, the broader internet, or just my son. Even though he uses HM, using ./scrip.sh is much easier for him then $(nix-build ./foo.nix --print-outpath) or whatever. Not to speak about the fact, that this requires often more than one file to be shared.
While obviously my preferred method is to package the scripts with nix and thus give them an absolute store path for the shebang, people new to the ecosystem, or unsure how much they want to invest into it, need low-effort ways to make their existing scripts work. Using /usr/bin/env is a reasonable suggestion for that niche. I am uncomfortable putting it down too much because of that. It’s not the ideal, but it’s a step on the road. We should present it as such.
Yeah, I agree it’s fine to do this. I use these shebangs from time to time too.
As I say, evaluate your use cases yourself. If you’re new and you can’t figure out pkgs.write*, just use it.
I don’t think however we should be declaring #!/usr/bin/env as the preferred way to write shebangs in the NixOS world, which is what @crertel 's comment reads like to me.