From d113e4e06e487ea693e6af68f2431b9da14636be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Mon, 28 Mar 2022 22:56:49 +0200 Subject: [PATCH] nixos/networkd: add `wait-online` options --- .../from_md/release-notes/rl-2205.section.xml | 29 ++++++++++ .../manual/release-notes/rl-2205.section.md | 5 ++ nixos/modules/system/boot/networkd.nix | 53 ++++++++++++++++++- 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index 830b0c2efcd3..ed6c49f02bbd 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -1316,6 +1316,35 @@ versions. + + + A new option group + systemd.network.wait-online was added, with + options to configure + systemd-networkd-wait-online.service: + + + + + anyInterface allows specifying that the + network should be considered online when at + least one interface is online (useful on + laptops) + + + + + timeout defines how long to wait for + the network to come online + + + + + extraArgs for everything else + + + + The influxdb2 package was split into diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 91ca2882ef12..60995731d3d5 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -478,6 +478,11 @@ In addition to numerous new and upgraded packages, this release has the followin still under heavy development and behavior is not always flawless. Furthermore, not all Electron apps use the latest Electron versions. +- A new option group `systemd.network.wait-online` was added, with options to configure `systemd-networkd-wait-online.service`: + - `anyInterface` allows specifying that the network should be considered online when *at least one* interface is online (useful on laptops) + - `timeout` defines how long to wait for the network to come online + - `extraArgs` for everything else + - The `influxdb2` package was split into `influxdb2-server` and `influxdb2-cli`, matching the split that took place upstream. A combined `influxdb2` package is still provided in this release for diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index ac1e4ef34b46..092b7b8863ae 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -1741,6 +1741,48 @@ in })); }; + systemd.network.wait-online = { + anyInterface = mkOption { + description = '' + Whether to consider the network online when any interface is online, as opposed to all of them. + This is useful on portable machines with a wired and a wireless interface, for example. + ''; + type = types.bool; + default = false; + }; + + ignoredInterfaces = mkOption { + description = '' + Network interfaces to be ignored when deciding if the system is online. + ''; + type = with types; listOf str; + default = []; + example = [ "wg0" ]; + }; + + timeout = mkOption { + description = '' + Time to wait for the network to come online, in seconds. Set to 0 to disable. + ''; + type = types.ints.unsigned; + default = 120; + example = 0; + }; + + extraArgs = mkOption { + description = '' + Extra command-line arguments to pass to systemd-networkd-wait-online. + These also affect per-interface systemd-network-wait-online@ services. + + See + systemd-networkd-wait-online.service8 + for all available options. + ''; + type = with types; listOf str; + default = []; + }; + }; + }; config = mkMerge [ @@ -1749,6 +1791,11 @@ in { systemd.network.units = mapAttrs' (n: v: nameValuePair "${n}.link" (linkToUnit n v)) cfg.links; environment.etc = unitFiles; + + systemd.network.wait-online.extraArgs = + [ "--timeout=${toString cfg.wait-online.timeout}" ] + ++ optional cfg.wait-online.anyInterface "--any" + ++ map (i: "--ignore=${i}") cfg.wait-online.ignoredInterfaces; } (mkIf config.systemd.network.enable { @@ -1777,6 +1824,10 @@ in systemd.services.systemd-networkd-wait-online = { wantedBy = [ "network-online.target" ]; + serviceConfig.ExecStart = [ + "" + "${config.systemd.package}/lib/systemd/systemd-networkd-wait-online ${utils.escapeSystemdExecArgs cfg.wait-online.extraArgs}" + ]; }; systemd.services."systemd-network-wait-online@" = { @@ -1787,7 +1838,7 @@ in serviceConfig = { Type = "oneshot"; RemainAfterExit = true; - ExecStart = "${config.systemd.package}/lib/systemd/systemd-networkd-wait-online -i %I"; + ExecStart = "${config.systemd.package}/lib/systemd/systemd-networkd-wait-online -i %I ${utils.escapeSystemdExecArgs cfg.wait-online.extraArgs}"; }; };