From 237f7ba7d2b2be46049e3327eb8208b5ac450940 Mon Sep 17 00:00:00 2001 From: ign0tus Date: Thu, 28 Sep 2023 17:04:35 +0200 Subject: [PATCH] networkd: Allow combinations of WakeOnLan policies To comply with the systemd.link WakeOnLan[^1] specification, the option "off" and all other possible policy combinations must be allowed. [^1]: https://www.freedesktop.org/software/systemd/man/systemd.link.html#WakeOnLan= --- nixos/lib/systemd-lib.nix | 4 ++++ nixos/modules/system/boot/networkd.nix | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index f6535b51406..5669aae0bc1 100644 --- a/nixos/lib/systemd-lib.nix +++ b/nixos/lib/systemd-lib.nix @@ -80,6 +80,10 @@ in rec { optional (attr ? ${name} && !elem attr.${name} values) "Systemd ${group} field `${name}' cannot have value `${toString attr.${name}}'."; + assertValuesSomeOfOr = name: values: default: group: attr: + optional (attr ? ${name} && !(all (x: elem x values) (splitString " " attr.${name}) || attr.${name} == default)) + "Systemd ${group} field `${name}' cannot have value `${toString attr.${name}}'."; + assertHasField = name: group: attr: optional (!(attr ? ${name})) "Systemd ${group} field `${name}' must exist."; diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 238c6670ea0..d203038dc32 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -83,7 +83,7 @@ let (assertByteFormat "BitsPerSecond") (assertValueOneOf "Duplex" ["half" "full"]) (assertValueOneOf "AutoNegotiation" boolValues) - (assertValueOneOf "WakeOnLan" ["phy" "unicast" "multicast" "broadcast" "arp" "magic" "secureon" "off"]) + (assertValuesSomeOfOr "WakeOnLan" ["phy" "unicast" "multicast" "broadcast" "arp" "magic" "secureon"] "off") (assertValueOneOf "Port" ["tp" "aui" "bnc" "mii" "fibre"]) (assertValueOneOf "ReceiveChecksumOffload" boolValues) (assertValueOneOf "TransmitChecksumOffload" boolValues)