handle simultaneous writes to stdout and $3
parent
dd8952be85
commit
696271700a
22
builder.nix
22
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
|
||||||
|
imported = (tryEval (let
|
||||||
# Needs to be done as nix chokes on empty files rn.
|
# Needs to be done as nix chokes on empty files rn.
|
||||||
content = readFile builder;
|
content = readFile builder;
|
||||||
in assert content != "" && (! (hasPrefix "#!" content)); import builder)).success
|
in assert content != "" && (! (hasPrefix "#!" content)); import builder));
|
||||||
then import builder
|
in if imported.success
|
||||||
else ''
|
then imported.value
|
||||||
|
else {
|
||||||
|
builder = ''
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
${/. + builder} $d1 $d2 $out >$out
|
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