You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stdenv: Errors in hooks (such as postUnpack) get ignored #7524
It seems that errors in stdenv hooks are being ignored.
For example, if I add this to pkgs/tools/networking/socat/default.nix:
postUnpack = ''
false
true
'';
Then when I run nix-build '<nixpkgs>' -A pkgs.socat, it will succeed even though it should fail, because a subcommand failed (the false subcommand).
I'm not completely sure about the following, but as far as I can see, the problem is that pkgs/stdenv/generic/setup.sh has this code:
15 runHook() {
16 local hookName="$1"
17 shift
18 local var="$hookName"
19 if [[ "$hookName"=~ Hook$ ]];then var+=s;else var+=Hooks;fi
20 eval"local -a dummy=(\"\${$var[@]}\")"
21 forhookin"_callImplicitHook 0 $hookName""${dummy[@]}";do
22 if! _eval "$hook""$@";thenreturn 1;fi
23 done
24 return 0
25 }
In line 22, we are evaluating the hook in the context of an if condition.
According to this comment, POSIX specifies that set -e gets ignored if we're running inside an if condition. And it seems that there is nothing that we can do to get set -e to be obeyed when running inside that context, not even starting a subshell...
I noticed lately ignored errors in some phases. This seems the source of the problem, thanks for finding it!
Suggestion: in this if-case we can just directly run the hook without any if, right? It seems only to propagate the error, but -e should do it for us I hope.
/cc author @edolstra. From a quick skim, runOneHook is also a problem. But it seems fixable – in any case, I think we can always first run the command separately and then run if on $?.
runOneHook seems to be a different story. It looks like this function is supposed to try out different hooks until it finds one that succeeds. So it would make more sense to leave the call for the hook inside of the if statement but pass a -e option to the subshell the executes the hook.
# Run all hooks with the specified name, until one succeeds (returns a
# zero exit code). If none succeed, return a non-zero exit code.
runOneHook() {
...
}
So it would make more sense to leave the call for the hook inside of the if statement but pass a -e option to the subshell the executes the hook.
But based on the comment I linked above, I thought that if we're inside the if statement, then the -e option will not have any effect, even if we run it inside a subshell?
However, the runOneHook case is basically unfixable. We can't run the hook in an if because that will disable -e, and we can't execute it outside of an if because that will cause the shell to exit. Executing in a subshell is not really an option because the assumption has always been that hooks run in the same shell (e.g. variables set by a hook should be visible outside). Though maybe we should just specify that certain hooks are executed in subshells.
Bash is a terrible, terrible programming language.
However, the runOneHook case is basically unfixable. We can't run the
hook in an if because that will disable -e, and we can't execute it
outside of an if because that will cause the shell to exit. Executing in
a subshell is not really an option because the assumption has always been
that hooks run in the same shell (e.g. variables set by a hook should be
visible outside). Though maybe we should just specify that certain hooks
are executed in subshells.
Bash is a terrible, terrible programming language.
—
Reply to this email directly or view it on GitHub #7524 (comment).
Activity
vcunat commentedon Apr 23, 2015
I noticed lately ignored errors in some phases. This seems the source of the problem, thanks for finding it!
Suggestion: in this if-case we can just directly run the hook without any if, right? It seems only to propagate the error, but
-eshould do it for us I hope.vcunat commentedon Apr 23, 2015
/cc author @edolstra. From a quick skim,
runOneHookis also a problem. But it seems fixable – in any case, I think we can always first run the command separately and then runifon$?.seppeljordan commentedon Apr 24, 2015
runOneHookseems to be a different story. It looks like this function is supposed to try out different hooks until it finds one that succeeds. So it would make more sense to leave the call for the hook inside of the if statement but pass a-eoption to the subshell the executes the hook.wizeman commentedon Apr 24, 2015
But based on the comment I linked above, I thought that if we're inside the if statement, then the
-eoption will not have any effect, even if we run it inside a subshell?seppeljordan commentedon Apr 24, 2015
Yes you are right, but I meant some construct like this:
Then we still have the possibility to try out different hooks until one succeeds but can catch errors inside of the hooks.
edolstra commentedon May 12, 2015
runHookis easy to fix, I'll push a fix soon.However, the
runOneHookcase is basically unfixable. We can't run the hook in anifbecause that will disable-e, and we can't execute it outside of anifbecause that will cause the shell to exit. Executing in a subshell is not really an option because the assumption has always been that hooks run in the same shell (e.g. variables set by a hook should be visible outside). Though maybe we should just specify that certain hooks are executed in subshells.Bash is a terrible, terrible programming language.
wkennington commentedon May 12, 2015
Maybe it's time for a better programming language in the stdenv? There is
always awk which we have :).
On Tue, May 12, 2015, 09:40 Eelco Dolstra [email protected] wrote:
Ensure that errexit is honoured in hooks
Fix inputproto and probably other packages
systemd: Fix another build failure hidden by #7524
Fix usbutils
wpa_supplicant: Fix build
9 remaining items
Merge pull request #8527 from dezgeg/pr-xfig
crackxls: Fix build
libxcomp: Fix build
mbedtls: Fix build
libreoffice: work around a build problem
buildRustPackage: Fix rust builds due to #7524
linux-rpi: Fix modDirVersion
stdenv/multiple-outputs: Guard greps with 'set +/-o pipefail'