I’m packaging a Bash script that has a few runtime dependencies.
I’m using substitute
to patch the shebang, but for the other dependencies it seems like I could either use substitute
to patch in absolute paths or use wrapProgram
to add the dependencies to the PATH
.
Are there pros / cons I should take into consideration when making this decision?
To illustrate, a way oversimplified example might be a trivial bash script ./foo
like,
#! /usr/bin/env bash
git log --pretty=oneline
If the default.nix substituted absolute paths to the script’s runtime dependencies, it might look like,
{ git, lib, runCommand, runtimeShell }:
runCommand "foo" { } ''
mkdir -p $out/bin
substitute ${./foo} $out/bin/foo \
--replace '/usr/bin/env bash' ${runtimeShell} \
--replace git ${git}/bin/git
chmod +x $out/bin/foo
''
If instead it added dependencies to PATH
, it could look like,
{ git, lib, makeWrapper, runCommand, runtimeShell }:
runCommand "foo" {
nativeBuildInputs = [ makeWrapper ];
} ''
mkdir -p $out/bin
substitute ${./foo} $out/bin/foo \
--replace '/usr/bin/env bash' ${runtimeShell}
chmod +x $out/bin/foo
wrapProgram $out/bin/foo \
--prefix PATH : "${lib.makeBinPath [ git ]}"
''