From a998d196ab124b32a0316efba132a9eb73f90480 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Tue, 6 Jan 2026 23:50:10 +0200 Subject: [PATCH] nixos/switchable-system: only include the switch-inhibitors check when we have inhibitors --- .../system/activation/switchable-system.nix | 111 +++++++++--------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/nixos/modules/system/activation/switchable-system.nix b/nixos/modules/system/activation/switchable-system.nix index c7261a8336a6..45b5caac7734 100644 --- a/nixos/modules/system/activation/switchable-system.nix +++ b/nixos/modules/system/activation/switchable-system.nix @@ -78,68 +78,69 @@ sha256sum = lib.getExe' pkgs.coreutils "sha256sum"; diff = lib.getExe' pkgs.diffutils "diff"; in - # bash - '' - incoming="''${1-}" - action="''${2-}" + lib.mkIf (lib.length config.system.switch.inhibitors > 0) + # bash + '' + incoming="''${1-}" + action="''${2-}" - if [ "$action" == "boot" ]; then - echo "Not checking switch inhibitors (action = $action)" - exit - fi - - echo -n "Checking switch inhibitors..." - - booted_inhibitors="$(${realpath} /run/booted-system)/switch-inhibitors" - booted_inhibitors_sha="$( - if [ -f "$booted_inhibitors" ]; then - ${sha256sum} - < "$booted_inhibitors" - else - echo 'none' + if [ "$action" == "boot" ]; then + echo "Not checking switch inhibitors (action = $action)" + exit fi - )" - if [ "$booted_inhibitors_sha" == "none" ]; then - echo - echo "The previous configuration did not specify switch inhibitors, nothing to check." - exit - fi + echo -n "Checking switch inhibitors..." - new_inhibitors="$(${realpath} "$incoming")/switch-inhibitors" - new_inhibitors_sha="$( - if [ -f "$new_inhibitors" ]; then - ${sha256sum} - < "$new_inhibitors" - else - echo 'none' + booted_inhibitors="$(${realpath} /run/booted-system)/switch-inhibitors" + booted_inhibitors_sha="$( + if [ -f "$booted_inhibitors" ]; then + ${sha256sum} - < "$booted_inhibitors" + else + echo 'none' + fi + )" + + if [ "$booted_inhibitors_sha" == "none" ]; then + echo + echo "The previous configuration did not specify switch inhibitors, nothing to check." + exit fi - )" - if [ "$new_inhibitors_sha" == "none" ]; then - echo - echo "The new configuration does not specify switch inhibitors, nothing to check." - exit - fi + new_inhibitors="$(${realpath} "$incoming")/switch-inhibitors" + new_inhibitors_sha="$( + if [ -f "$new_inhibitors" ]; then + ${sha256sum} - < "$new_inhibitors" + else + echo 'none' + fi + )" - if [ "$new_inhibitors_sha" != "$booted_inhibitors_sha" ]; then - echo - echo "Found diff in switch inhibitors:" - echo - ${diff} --color "$booted_inhibitors" "$new_inhibitors" - echo - echo "The new configuration contains changes to packages that were" - echo "listed as switch inhibitors." - echo "You probably want to run 'nixos-rebuild boot' and reboot your system." - echo - echo "If you really want to switch into this configuration directly, then" - echo "you can set NIXOS_NO_CHECK=1 to ignore pre-switch checks." - echo - echo "WARNING: doing so might cause the switch to fail or your system to become unstable." - echo - exit 1 - else - echo " done" - fi - ''; + if [ "$new_inhibitors_sha" == "none" ]; then + echo + echo "The new configuration does not specify switch inhibitors, nothing to check." + exit + fi + + if [ "$new_inhibitors_sha" != "$booted_inhibitors_sha" ]; then + echo + echo "Found diff in switch inhibitors:" + echo + ${diff} --color "$booted_inhibitors" "$new_inhibitors" + echo + echo "The new configuration contains changes to packages that were" + echo "listed as switch inhibitors." + echo "You probably want to run 'nixos-rebuild boot' and reboot your system." + echo + echo "If you really want to switch into this configuration directly, then" + echo "you can set NIXOS_NO_CHECK=1 to ignore pre-switch checks." + echo + echo "WARNING: doing so might cause the switch to fail or your system to become unstable." + echo + exit 1 + else + echo " done" + fi + ''; }; }; }