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.
This commit is contained in:
Andrew Marshall 2022-08-14 00:33:24 -04:00
parent c8565c74bc
commit 189b14246a

View file

@ -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" ];