Hashbang when using `substituteAll` to build a shell script

I’m extracting a shell script which on master is written inline as a string in a .nix file, moving it into a .sh file so that we can run tooling against it. Here’s what it looks like after my change:

fetch-deps = substituteAll {
  src = ./fetchDeps.sh;
  inherit pname defaultDepsFile runtimeIds storeSrc flags disableParallel
    projectFileStr testProjectFileStr path dotnetSdkPath excludedSources;
};

Here, my fetchDeps.sh starts like this:

set -euo pipefail

export PATH="@path@"

This is all working exactly as I had hoped, except of course that the result of substituteAll does not have a hashbang at the top, so it’s not an executable.

What’s the idiomatic way to do this? Should I just define like bash = ''${pkgs.bash}/bin/bash'' and substitute that in with #!@bash@ (icky! would be nice if this template file either had no hashbang or a valid hashbang), or is there a cleaner way to do this?

Maybe use ${pkgs.runtimeShell} instead of ${pkgs.bash}/bin/bash, but yeah, I’ve seen substituteAll used like this.

1 Like

Don’t have the time to read the PR closely atm but I do wonder from the basics if this could be using writeShellApplication?

Oh amazing, I hand-rolled my own version of that elsewhere because I didn’t know it existed!

1 Like