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.
|
# Funktionalise pkgs; our main entry point to resolve default*nix build scripts.
|
||||||
funcPkgs = { __functor = self: arg: resolve arg; } // pkgs;
|
funcPkgs = { __functor = self: arg: resolve arg; } // pkgs;
|
||||||
|
|
||||||
_builder = if (tryEval (let
|
_builder = let
|
||||||
# Needs to be done as nix chokes on empty files rn.
|
imported = (tryEval (let
|
||||||
content = readFile builder;
|
# Needs to be done as nix chokes on empty files rn.
|
||||||
in assert content != "" && (! (hasPrefix "#!" content)); import builder)).success
|
content = readFile builder;
|
||||||
then import builder
|
in assert content != "" && (! (hasPrefix "#!" content)); import builder));
|
||||||
else ''
|
in if imported.success
|
||||||
#!/bin/sh
|
then imported.value
|
||||||
${/. + builder} $d1 $d2 $out >$out
|
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
|
__builder = if isFunction _builder then _builder funcPkgs
|
||||||
else _builder;
|
else _builder;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue