1
0
Fork 0

handle simultaneous writes to stdout and $3

master
Michael Raitza 2021-02-17 09:12:23 +01:00
parent dd8952be85
commit 696271700a
1 changed files with 21 additions and 9 deletions

View File

@ -14,15 +14,27 @@ let
# Funktionalise pkgs; our main entry point to resolve default*nix build scripts.
funcPkgs = { __functor = self: arg: resolve arg; } // pkgs;
_builder = if (tryEval (let
# Needs to be done as nix chokes on empty files rn.
content = readFile builder;
in assert content != "" && (! (hasPrefix "#!" content)); import builder)).success
then import builder
else ''
#!/bin/sh
${/. + builder} $d1 $d2 $out >$out
'';
_builder = let
imported = (tryEval (let
# Needs to be done as nix chokes on empty files rn.
content = readFile builder;
in assert content != "" && (! (hasPrefix "#!" content)); import builder));
in if imported.success
then imported.value
else {
builder = ''
#!/bin/sh
set -e
pout=$(mktemp -u -p $PWD)
${/. + builder} $d1 $d2 $out >$pout
if [ -e $out -a -s $pout ]; then
printf "Error: %s wrote to stdout and created \$3\n" "$d1" >&2
exit 207
elif [ -s $pout ]; then
mv $pout $out
fi
'';
};
__builder = if isFunction _builder then _builder funcPkgs
else _builder;