···390390 include serif fonts.
391391 </para>
392392 </listitem>
393393+ <listitem>
394394+ <para>
395395+ The interface that allows activation scripts to restart units
396396+ has been reworked. Restarting and reloading is now done by a
397397+ single file
398398+ <literal>/run/nixos/activation-restart-list</literal> that
399399+ honors <literal>restartIfChanged</literal> and
400400+ <literal>reloadIfChanged</literal> of the units.
401401+ </para>
402402+ </listitem>
393403 </itemizedlist>
394404 </section>
395405 <section xml:id="sec-release-22.05-notable-changes">
+2
nixos/doc/manual/release-notes/rl-2205.section.md
···125125 `pkgs.noto-fonts-cjk` is currently an alias of `pkgs.noto-fonts-cjk-sans` and
126126 doesn't include serif fonts.
127127128128+- The interface that allows activation scripts to restart units has been reworked. Restarting and reloading is now done by a single file `/run/nixos/activation-restart-list` that honors `restartIfChanged` and `reloadIfChanged` of the units.
129129+128130## Other Notable Changes {#sec-release-22.05-notable-changes}
129131130132- The option [services.redis.servers](#opt-services.redis.servers) was added
+17-1
nixos/modules/services/networking/adguardhome.nix
···8787 };
88888989 config = mkIf cfg.enable {
9090+ assertions = [
9191+ {
9292+ assertion = cfg.settings != { }
9393+ -> (hasAttrByPath [ "dns" "bind_host" ] cfg.settings)
9494+ || (hasAttrByPath [ "dns" "bind_hosts" ] cfg.settings);
9595+ message =
9696+ "AdGuard setting dns.bind_host or dns.bind_hosts needs to be configured for a minimal working configuration";
9797+ }
9898+ {
9999+ assertion = cfg.settings != { }
100100+ -> hasAttrByPath [ "dns" "bootstrap_dns" ] cfg.settings;
101101+ message =
102102+ "AdGuard setting dns.bootstrap_dns needs to be configured for a minimal working configuration";
103103+ }
104104+ ];
105105+90106 systemd.services.adguardhome = {
91107 description = "AdGuard Home: Network-level blocker";
92108 after = [ "network.target" ];
···96112 StartLimitBurst = 10;
97113 };
981149999- preStart = ''
115115+ preStart = optionalString (cfg.settings != { }) ''
100116 if [ -e "$STATE_DIRECTORY/AdGuardHome.yaml" ] \
101117 && [ "${toString cfg.mutableSettings}" = "1" ]; then
102118 # Writing directly to AdGuardHome.yaml results in empty file
···1818my $restartListFile = "/run/nixos/restart-list";
1919my $reloadListFile = "/run/nixos/reload-list";
20202121-# Parse restart/reload requests by the activation script
2121+# Parse restart/reload requests by the activation script.
2222+# Activation scripts may write newline-separated units to this
2323+# file and switch-to-configuration will handle them. While
2424+# `stopIfChanged = true` is ignored, switch-to-configuration will
2525+# handle `restartIfChanged = false` and `reloadIfChanged = true`.
2226my $restartByActivationFile = "/run/nixos/activation-restart-list";
2323-my $reloadByActivationFile = "/run/nixos/activation-reload-list";
2427my $dryRestartByActivationFile = "/run/nixos/dry-activation-restart-list";
2525-my $dryReloadByActivationFile = "/run/nixos/dry-activation-reload-list";
26282729make_path("/run/nixos", { mode => oct(755) });
2830···382384}
383385384386my @unitsToStopFiltered = filterUnits(\%unitsToStop);
385385-my @unitsToStartFiltered = filterUnits(\%unitsToStart);
386387387388388389# Show dry-run actions.
···395396 print STDERR "would activate the configuration...\n";
396397 system("$out/dry-activate", "$out");
397398398398- $unitsToRestart{$_} = 1 foreach
399399- split('\n', read_file($dryRestartByActivationFile, err_mode => 'quiet') // "");
399399+ # Handle the activation script requesting the restart or reload of a unit.
400400+ foreach (split('\n', read_file($dryRestartByActivationFile, err_mode => 'quiet') // "")) {
401401+ my $unit = $_;
402402+ my $baseUnit = $unit;
403403+ my $newUnitFile = "$out/etc/systemd/system/$baseUnit";
400404401401- $unitsToReload{$_} = 1 foreach
402402- split('\n', read_file($dryReloadByActivationFile, err_mode => 'quiet') // "");
405405+ # Detect template instances.
406406+ if (!-e $newUnitFile && $unit =~ /^(.*)@[^\.]*\.(.*)$/) {
407407+ $baseUnit = "$1\@.$2";
408408+ $newUnitFile = "$out/etc/systemd/system/$baseUnit";
409409+ }
410410+411411+ my $baseName = $baseUnit;
412412+ $baseName =~ s/\.[a-z]*$//;
413413+414414+ # Start units if they were not active previously
415415+ if (not defined $activePrev->{$unit}) {
416416+ $unitsToStart{$unit} = 1;
417417+ next;
418418+ }
419419+420420+ handleModifiedUnit($unit, $baseName, $newUnitFile, $activePrev, \%unitsToRestart, \%unitsToRestart, \%unitsToReload, \%unitsToRestart, \%unitsToSkip);
421421+ }
422422+ unlink($dryRestartByActivationFile);
403423404424 print STDERR "would restart systemd\n" if $restartSystemd;
405425 print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n"
406426 if scalar(keys %unitsToReload) > 0;
407427 print STDERR "would restart the following units: ", join(", ", sort(keys %unitsToRestart)), "\n"
408428 if scalar(keys %unitsToRestart) > 0;
429429+ my @unitsToStartFiltered = filterUnits(\%unitsToStart);
409430 print STDERR "would start the following units: ", join(", ", @unitsToStartFiltered), "\n"
410431 if scalar @unitsToStartFiltered;
411411- unlink($dryRestartByActivationFile);
412412- unlink($dryReloadByActivationFile);
413432 exit 0;
414433}
415434···433452system("$out/activate", "$out") == 0 or $res = 2;
434453435454# Handle the activation script requesting the restart or reload of a unit.
436436-# We can only restart and reload (not stop/start) because the units to be
437437-# stopped are already stopped before the activation script is run.
438438-$unitsToRestart{$_} = 1 foreach
439439- split('\n', read_file($restartByActivationFile, err_mode => 'quiet') // "");
455455+foreach (split('\n', read_file($restartByActivationFile, err_mode => 'quiet') // "")) {
456456+ my $unit = $_;
457457+ my $baseUnit = $unit;
458458+ my $newUnitFile = "$out/etc/systemd/system/$baseUnit";
440459441441-$unitsToReload{$_} = 1 foreach
442442- split('\n', read_file($reloadByActivationFile, err_mode => 'quiet') // "");
460460+ # Detect template instances.
461461+ if (!-e $newUnitFile && $unit =~ /^(.*)@[^\.]*\.(.*)$/) {
462462+ $baseUnit = "$1\@.$2";
463463+ $newUnitFile = "$out/etc/systemd/system/$baseUnit";
464464+ }
465465+466466+ my $baseName = $baseUnit;
467467+ $baseName =~ s/\.[a-z]*$//;
468468+469469+ # Start units if they were not active previously
470470+ if (not defined $activePrev->{$unit}) {
471471+ $unitsToStart{$unit} = 1;
472472+ recordUnit($startListFile, $unit);
473473+ next;
474474+ }
475475+476476+ handleModifiedUnit($unit, $baseName, $newUnitFile, $activePrev, \%unitsToRestart, \%unitsToRestart, \%unitsToReload, \%unitsToRestart, \%unitsToSkip);
477477+}
478478+# We can remove the file now because it has been propagated to the other restart/reload files
479479+unlink($restartByActivationFile);
443480444481# Restart systemd if necessary. Note that this is done using the
445482# current version of systemd, just in case the new one has trouble
···480517 print STDERR "reloading the following units: ", join(", ", sort(keys %unitsToReload)), "\n";
481518 system("@systemd@/bin/systemctl", "reload", "--", sort(keys %unitsToReload)) == 0 or $res = 4;
482519 unlink($reloadListFile);
483483- unlink($reloadByActivationFile);
484520}
485521486522# Restart changed services (those that have to be restarted rather
···489525 print STDERR "restarting the following units: ", join(", ", sort(keys %unitsToRestart)), "\n";
490526 system("@systemd@/bin/systemctl", "restart", "--", sort(keys %unitsToRestart)) == 0 or $res = 4;
491527 unlink($restartListFile);
492492- unlink($restartByActivationFile);
493528}
494529495530# Start all active targets, as well as changed units we stopped above.
···498533# that are symlinks to other units. We shouldn't start both at the
499534# same time because we'll get a "Failed to add path to set" error from
500535# systemd.
536536+my @unitsToStartFiltered = filterUnits(\%unitsToStart);
501537print STDERR "starting the following units: ", join(", ", @unitsToStartFiltered), "\n"
502538 if scalar @unitsToStartFiltered;
503539system("@systemd@/bin/systemctl", "start", "--", sort(keys %unitsToStart)) == 0 or $res = 4;