diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index 8397eca39c51..13c529d53619 100644 --- a/nixos/lib/systemd-lib.nix +++ b/nixos/lib/systemd-lib.nix @@ -278,6 +278,21 @@ rec { attr ? ${name} && !(hasPrefix "@" attr.${name}) ) "Systemd ${group} field `${name}' is not a systemd credential"; + assertRouteMetricOrTriple = + name: group: attr: + let + isMetric = n: 0 <= n && 4294967295 >= n; + + parts = splitString ":" attr.${name}; + partsValid = + length parts == 3 && all (p: (match "[0-9]+" p) != null && isMetric (toIntBase10 p)) parts; + valid = (isInt attr.${name} && isMetric attr.${name}) || partsValid; + in + optional (attr ? ${name} && !valid) ( + "Systemd ${group} field `${name}' must either be an integer in the range [0,4294967295]" + + " or a string containing three integers separated with `:`" + ); + checkUnitConfig = group: checks: attrs: let diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 0c74115c15a4..d9f368834e1f 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -1744,8 +1744,7 @@ let (assertValueOneOf "UseDNR" boolValues) (assertValueOneOf "UseDomains" (boolValues ++ [ "route" ])) (assertRange "RouteTable" 0 4294967295) - (assertInt "RouteMetric") - (assertRange "RouteMetric" 0 4294967295) + (assertRouteMetricOrTriple "RouteMetric") (assertValueOneOf "QuickAck" boolValues) (assertValueOneOf "UseMTU" boolValues) (assertValueOneOf "UseHopLimit" boolValues)