Merge pull request #186503 from Weathercold/patch-1

nixos/switch-to-configuration: fix units starting with dash not being able to reload

Stig 8c4a3b27 262f2f58

Changed files
+39 -2
nixos
modules
system
tests
+1 -1
nixos/modules/system/activation/switch-to-configuration.pl
···
# Takes the name of the unit as an argument and returns a bool whether the unit is active or not.
sub unit_is_active {
my ($unit_name) = @_;
-
my $units = busctl_call_systemd1_mgr("ListUnitsByNames", "as", 1, $unit_name)->{data}->[0];
if (scalar(@{$units}) == 0) {
return 0;
}
···
# Takes the name of the unit as an argument and returns a bool whether the unit is active or not.
sub unit_is_active {
my ($unit_name) = @_;
+
my $units = busctl_call_systemd1_mgr("ListUnitsByNames", "as", 1, , "--", $unit_name)->{data}->[0];
if (scalar(@{$units}) == 0) {
return 0;
}
+38 -1
nixos/tests/switch-test.nix
···
systemd.services."escaped\\x2ddash".serviceConfig.X-Test = "test";
};
unitWithRequirement.configuration = {
systemd.services.required-service = {
wantedBy = [ "multi-user.target" ];
···
assert_contains(out, "\nstarting the following units: escaped\\x2ddash.service\n")
assert_lacks(out, "the following new units were started:")
# Ensure units that require changed units are properly reloaded
out = switch_to_specialisation("${machine}", "unitWithRequirement")
-
assert_contains(out, "stopping the following units: escaped\\x2ddash.service\n")
assert_lacks(out, "NOT restarting the following changed units:")
assert_lacks(out, "reloading the following units:")
assert_lacks(out, "\nrestarting the following units:")
···
systemd.services."escaped\\x2ddash".serviceConfig.X-Test = "test";
};
+
unitStartingWithDash.configuration = {
+
systemd.services."-" = {
+
wantedBy = [ "multi-user.target" ];
+
serviceConfig = {
+
Type = "oneshot";
+
RemainAfterExit = true;
+
ExecStart = "${pkgs.coreutils}/bin/true";
+
};
+
};
+
};
+
+
unitStartingWithDashModified.configuration = {
+
imports = [ unitStartingWithDash.configuration ];
+
systemd.services."-" = {
+
reloadIfChanged = true;
+
serviceConfig.ExecReload = "${pkgs.coreutils}/bin/true";
+
};
+
};
+
unitWithRequirement.configuration = {
systemd.services.required-service = {
wantedBy = [ "multi-user.target" ];
···
assert_contains(out, "\nstarting the following units: escaped\\x2ddash.service\n")
assert_lacks(out, "the following new units were started:")
+
# Ensure units can start with a dash
+
out = switch_to_specialisation("${machine}", "unitStartingWithDash")
+
assert_contains(out, "stopping the following units: escaped\\x2ddash.service\n")
+
assert_lacks(out, "NOT restarting the following changed units:")
+
assert_lacks(out, "reloading the following units:")
+
assert_lacks(out, "\nrestarting the following units:")
+
assert_lacks(out, "\nstarting the following units:")
+
assert_contains(out, "the following new units were started: -.service\n")
+
+
# The regression only occurs when reloading units
+
out = switch_to_specialisation("${machine}", "unitStartingWithDashModified")
+
assert_lacks(out, "stopping the following units:")
+
assert_lacks(out, "NOT restarting the following changed units:")
+
assert_contains(out, "reloading the following units: -.service")
+
assert_lacks(out, "\nrestarting the following units:")
+
assert_lacks(out, "\nstarting the following units:")
+
assert_lacks(out, "the following new units were started:")
+
# Ensure units that require changed units are properly reloaded
out = switch_to_specialisation("${machine}", "unitWithRequirement")
+
assert_contains(out, "stopping the following units: -.service\n")
assert_lacks(out, "NOT restarting the following changed units:")
assert_lacks(out, "reloading the following units:")
assert_lacks(out, "\nrestarting the following units:")