From 189b14246a1992ff2454f75ae3478141fed2488b Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 14 Aug 2022 00:33:24 -0400 Subject: [PATCH] nixos/networkd: Reload (not restart) when only .network units change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Underneath, systemd-networkd’s reload is just `networkctl reload`. Per `man networkctl`, calling `reload` is expected to fully handle new, modified, and removed .network files, but it only handles *new* .netdev files. For simplicity, assume .network -> reload and .netdev -> restart. It’s desirable to perform reload instead of restart, as restart has the potential to bring down interfaces, resulting in a loss of network connectivity. --- nixos/modules/system/boot/networkd.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 6d0afcc57fc..756632a45f9 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -2812,9 +2812,16 @@ let environment.etc."systemd/networkd.conf" = renderConfig cfg.config; - systemd.services.systemd-networkd = { + systemd.services.systemd-networkd = let + isReloadableUnitFileName = unitFileName: strings.hasSuffix ".network" unitFileName; + partitionedUnitFiles = lib.partition isReloadableUnitFileName unitFiles; + reloadableUnitFiles = partitionedUnitFiles.right; + nonReloadableUnitFiles = partitionedUnitFiles.wrong; + unitFileSources = unitFiles: map (x: x.source) (attrValues unitFiles); + in { wantedBy = [ "multi-user.target" ]; - restartTriggers = map (x: x.source) (attrValues unitFiles) ++ [ + reloadTriggers = unitFileSources reloadableUnitFiles; + restartTriggers = unitFileSources nonReloadableUnitFiles ++ [ config.environment.etc."systemd/networkd.conf".source ]; aliases = [ "dbus-org.freedesktop.network1.service" ];