diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 4289740322a..655fbab2a84 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -97,7 +97,7 @@ sub parseFstab { sub parseUnit { my ($filename) = @_; my $info = {}; - parseKeyValues($info, read_file($filename)); + parseKeyValues($info, read_file($filename)) if -f $filename; parseKeyValues($info, read_file("${filename}.d/overrides.conf")) if -f "${filename}.d/overrides.conf"; return $info; } @@ -157,7 +157,8 @@ while (my ($unit, $state) = each %{$activePrev}) { if (-e $prevUnitFile && ($state->{state} eq "active" || $state->{state} eq "activating")) { if (! -e $newUnitFile || abs_path($newUnitFile) eq "/dev/null") { - $unitsToStop{$unit} = 1; + my $unitInfo = parseUnit($prevUnitFile); + $unitsToStop{$unit} = 1 if boolIsTrue($unitInfo->{'X-StopOnRemoval'} // "yes"); } elsif ($unit =~ /\.target$/) {