nixos/networkd: add wait-online options

This commit is contained in:
Naïm Favier 2022-03-28 22:56:49 +02:00
parent ce8cbe3c01
commit d113e4e06e
No known key found for this signature in database
GPG key ID: 49B07322580B7EE2
3 changed files with 86 additions and 1 deletions

View file

@ -1316,6 +1316,35 @@
versions.
</para>
</listitem>
<listitem>
<para>
A new option group
<literal>systemd.network.wait-online</literal> was added, with
options to configure
<literal>systemd-networkd-wait-online.service</literal>:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>anyInterface</literal> allows specifying that the
network should be considered online when <emphasis>at
least one</emphasis> interface is online (useful on
laptops)
</para>
</listitem>
<listitem>
<para>
<literal>timeout</literal> defines how long to wait for
the network to come online
</para>
</listitem>
<listitem>
<para>
<literal>extraArgs</literal> for everything else
</para>
</listitem>
</itemizedlist>
</listitem>
<listitem>
<para>
The <literal>influxdb2</literal> package was split into

View file

@ -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

View file

@ -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 <literal>systemd-network-wait-online@</literal> services.
See <link xlink:href="https://www.freedesktop.org/software/systemd/man/systemd-networkd-wait-online.service.html">
<citerefentry><refentrytitle>systemd-networkd-wait-online.service</refentrytitle><manvolnum>8</manvolnum>
</citerefentry></link> 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}";
};
};