From 65ff0d5f9de3e8f0ca5ec3a70549e30afd84a6d5 Mon Sep 17 00:00:00 2001 From: danbst Date: Tue, 22 Aug 2017 15:04:18 +0300 Subject: [PATCH] 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. --- .../modules/system/activation/switch-to-configuration.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 88e7847cf8c..29cc60b0032 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -147,11 +147,16 @@ my $activePrev = getActiveUnits; while (my ($unit, $state) = each %{$activePrev}) { my $baseUnit = $unit; - # Recognise template instances. - $baseUnit = "$1\@.$2" if $unit =~ /^(.*)@[^\.]*\.(.*)$/; my $prevUnitFile = "/etc/systemd/system/$baseUnit"; my $newUnitFile = "$out/etc/systemd/system/$baseUnit"; + # Detect template instances. + if (!-e $prevUnitFile && !-e $newUnitFile && $unit =~ /^(.*)@[^\.]*\.(.*)$/) { + $baseUnit = "$1\@.$2"; + $prevUnitFile = "/etc/systemd/system/$baseUnit"; + $newUnitFile = "$out/etc/systemd/system/$baseUnit"; + } + my $baseName = $baseUnit; $baseName =~ s/\.[a-z]*$//;