lol

switch-to-configuration: fix detection of changes between rebuilds for template instances

This makes declarative containers truly reloadable. Current code already declares it:

https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/nixos/modules/virtualisation/containers.nix#L488

```
restartIfChanged = false;
```

https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/nixos/modules/virtualisation/containers.nix#L540

```
reloadIfChanged = true;
```

Original author: @chrisfarms in https://github.com/NixOS/nixpkgs/pull/3021/commits/6e36619b277f78ece1bb81b79b5651897e46a2bf
Most of stuff from that commit has already been ported.

danbst 65ff0d5f 37c34072

+7 -2
+7 -2
nixos/modules/system/activation/switch-to-configuration.pl
··· 147 147 while (my ($unit, $state) = each %{$activePrev}) { 148 148 my $baseUnit = $unit; 149 149 150 - # Recognise template instances. 151 - $baseUnit = "$1\@.$2" if $unit =~ /^(.*)@[^\.]*\.(.*)$/; 152 150 my $prevUnitFile = "/etc/systemd/system/$baseUnit"; 153 151 my $newUnitFile = "$out/etc/systemd/system/$baseUnit"; 152 + 153 + # Detect template instances. 154 + if (!-e $prevUnitFile && !-e $newUnitFile && $unit =~ /^(.*)@[^\.]*\.(.*)$/) { 155 + $baseUnit = "$1\@.$2"; 156 + $prevUnitFile = "/etc/systemd/system/$baseUnit"; 157 + $newUnitFile = "$out/etc/systemd/system/$baseUnit"; 158 + } 154 159 155 160 my $baseName = $baseUnit; 156 161 $baseName =~ s/\.[a-z]*$//;