Files
postgrest/nix/overlays/checked-shell-script/checked-shell-script.nix
T

40 lines
837 B
Nix

# Create a bash script that is checked with shellcheck. You can either use it
# directly, or use the .bin attribute to get the script in a bin/ directory,
# to be used in a path for example.
{ writeTextFile
, runtimeShell
, runCommand
, stdenv
, shellcheck
}:
name: text:
let
bin =
writeTextFile {
inherit name;
executable = true;
destination = "/bin/${name}";
text =
''
#!${runtimeShell}
set -euo pipefail
${text}
'';
checkPhase =
''
# check syntax
${stdenv.shell} -n $out/bin/${name}
# check for shellcheck recommendations
${shellcheck}/bin/shellcheck $out/bin/${name}
'';
};
script =
runCommand name { inherit bin name; } "ln -s $bin/bin/$name $out";
in
script // { inherit bin; }