nixos-config/machines/shinobu/services/router/nft.nix

34 lines
757 B
Nix
Raw Permalink Normal View History

{ config, lib, pkgs, ... }:
2023-09-24 14:41:22 +02:00
let
cfg = pkgs.callPackage ./common.nix { };
2023-09-24 14:41:22 +02:00
mkKeyValue = lib.generators.mkKeyValueDefault
rec {
mkValueString = v:
if lib.isString v then ''"${v}"''
else if lib.isList v then ''{ ${lib.concatMapStringsSep ", " mkValueString v} }''
else lib.generators.mkValueStringDefault { } v;
} " = ";
passthru = {
VLANS = lib.attrNames cfg.vlan;
VLAN_BRIDGES = map (name: "br-${name}") (lib.attrNames cfg.vlan);
};
2023-09-24 14:41:22 +02:00
defines = lib.concatStringsSep
"\n"
(lib.mapAttrsToList
(key: value: "define " + (mkKeyValue key value))
passthru);
2023-09-24 14:41:22 +02:00
in
{
networking.nftables = {
enable = true;
ruleset = ''
${defines}
include "${./rules.nft}"
'';
};
}