handle simultaneous writes to stdout and $3
parent
dd8952be85
commit
696271700a
30
builder.nix
30
builder.nix
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue