diff options
author | Andrew Marshall <andrew@johnandrewmarshall.com> | 2022-08-14 00:33:24 -0400 |
---|---|---|
committer | Andrew Marshall <andrew@johnandrewmarshall.com> | 2023-08-31 12:24:17 -0400 |
commit | 189b14246a1992ff2454f75ae3478141fed2488b (patch) | |
tree | c9971fe4b9ea0e629f8272aafc81b1db3b00c11e /nixos/modules/system/boot | |
parent | c8565c74bc3066efc3319e83ab63f85b9cab1a4d (diff) |
nixos/networkd: Reload (not restart) when only .network units change
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.
Diffstat (limited to 'nixos/modules/system/boot')
-rw-r--r-- | nixos/modules/system/boot/networkd.nix | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 6d0afcc57fcc6..756632a45f90a 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" ]; |