nix(refactor): Add withEnv to checked-shell-script

This commit is contained in:
Wolfgang Walther
2021-04-18 13:51:39 +02:00
committed by Wolfgang Walther
parent 40b1dccc54
commit 39d4646a4c
2 changed files with 16 additions and 15 deletions
@@ -9,8 +9,14 @@
, stdenv
, writeTextFile
}:
{ name, docs, inRootDir ? false, redirectTixFiles ? true, withTmpDir ? false }: text:
# TODO: do something sensible with docs, e.g. provide automated --help
{ name
, docs
, inRootDir ? false
, redirectTixFiles ? true
, withEnv ? null
, withTmpDir ? false
}: text:
let
bin =
writeTextFile {
@@ -46,6 +52,10 @@ let
# remove the tmpdir when cancelled (postgrest-watch)
trap 'rm -rf "$tmpdir"' SIGINT SIGTERM
''
+ lib.optionalString (withEnv != null) ''
env="$(cat ${withEnv})"
export PATH="$env/bin:$PATH"
''
+ "(${text})"
+ lib.optionalString withTmpDir ''