2024-09-22 11:26:36 +02:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 Simon Bruder <simon@sbruder.de>
|
2024-01-06 01:19:35 +01:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2023-10-18 20:04:04 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-09-24 14:41:22 +02:00
|
|
|
let
|
2023-10-18 20:04:04 +02:00
|
|
|
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;
|
|
|
|
} " = ";
|
|
|
|
|
2023-10-18 20:12:41 +02:00
|
|
|
passthru = {
|
|
|
|
VLANS = lib.attrNames cfg.vlan;
|
|
|
|
VLAN_BRIDGES = map (name: "br-${name}") (lib.attrNames cfg.vlan);
|
2024-09-22 11:26:36 +02:00
|
|
|
} // (lib.listToAttrs (lib.flatten (lib.mapAttrsToList
|
|
|
|
(name: staticHostConfig:
|
|
|
|
(map
|
|
|
|
(option: option // { name = "STATIC_HOST_${name}_${option.name}"; })
|
|
|
|
(lib.attrsToList staticHostConfig)))
|
|
|
|
cfg.staticHosts)));
|
2023-09-25 12:48:30 +02:00
|
|
|
|
2023-09-24 14:41:22 +02:00
|
|
|
defines = lib.concatStringsSep
|
|
|
|
"\n"
|
2023-09-25 12:48:30 +02:00
|
|
|
(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}"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|