Skip to content

Commit

Permalink
nixos/systemd-networkd: handle NFTSet = list
Browse files Browse the repository at this point in the history
  • Loading branch information
mvnetbiz committed Aug 7, 2024
1 parent 1173c27 commit fe764ef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions nixos/lib/systemd-lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,24 @@ in rec {

assertNftSet = name: group: attr:
let
defs = map (splitString ":") (filter (x: x != "") (splitString " " attr.${name}));
splitSets = def: map (splitString ":") (filter (x: x != "") (splitString " " def));
defs = if isString attr.${name} then splitSets attr.${name} else concatMap splitSets attr.${name};
get = xs: i: if length xs >= i + 1 then elemAt xs i else null;
assertNotNull = field: v: optional (v == null || v == "")
"Systemd ${group} field `${name}' ${field} must be specified.";
assertOneOf = field: values: v:
(assertNotNull field v) ++
(optional (v != null && !elem v values)
"Systemd ${group} field `${name}' ${field} cannot have value `${v}'.");
check = def: flatten [
check = def: [
(assertOneOf "source type" [ "address" "prefix" "ifindex" ] (get def 0))
(assertOneOf "address family" [ "arp" "bridge" "inet" "ip" "ip6" "netdev" ] (get def 1))
(assertNotNull "table name" (get def 2))
(assertNotNull "set name" (get def 3))
];
assertions =
if !isString attr.${name} then
[ "Systemd ${group} field `${name}' is not a string." ]
if ! (isString attr.${name} || isList attr.${name}) then
[ "Systemd ${group} field `${name}' is not a string or list of strings." ]
else
flatten (map check defs);
in
Expand Down

0 comments on commit fe764ef

Please sign in to comment.