Commit 189b1424 authored by Andrew Marshall's avatar Andrew Marshall
Browse files

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.
parent c8565c74
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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" ];