mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
[Backport release-26.05] nixos/preSwitchChecks: actually set errexit inside check bodies (#527909)
This commit is contained in:
commit
f458088f51
2 changed files with 21 additions and 2 deletions
|
|
@ -8,9 +8,18 @@ let
|
|||
preSwitchCheckScript = lib.concatLines (
|
||||
lib.mapAttrsToList (name: text: ''
|
||||
# pre-switch check ${name}
|
||||
if ! (
|
||||
#
|
||||
# Run with errexit in a subshell that is not part of an `if`/`||`
|
||||
# condition, so that `set -e` is actually honoured inside the
|
||||
# check body.
|
||||
set +e
|
||||
(
|
||||
set -e
|
||||
${text}
|
||||
) >&2 ; then
|
||||
) >&2
|
||||
_rc=$?
|
||||
set -e
|
||||
if [ "$_rc" -ne 0 ]; then
|
||||
echo "Pre-switch check '${name}' failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -788,6 +788,11 @@ in
|
|||
echo this will fail
|
||||
false
|
||||
'';
|
||||
specialisation.failingMidCheck.configuration.system.preSwitchChecks.failsInTheMiddle = ''
|
||||
echo before
|
||||
nonexistent-command
|
||||
echo after
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -888,6 +893,11 @@ in
|
|||
machine.succeed("${stderrRunner} ${otherSystem}/bin/switch-to-configuration check")
|
||||
out = switch_to_specialisation("${otherSystem}", "failingCheck", action="check", fail=True)
|
||||
assert_contains(out, "this will fail")
|
||||
# errexit must be honoured inside the check body
|
||||
out = switch_to_specialisation("${otherSystem}", "failingMidCheck", action="check", fail=True)
|
||||
assert_contains(out, "before")
|
||||
assert_contains(out, "Pre-switch check 'failsInTheMiddle' failed")
|
||||
assert_lacks(out, "after")
|
||||
|
||||
with subtest("switch inhibitors"):
|
||||
# Start without any inhibitors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue