2024-12-19 20:25:01 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
utils,
|
2024-12-21 20:57:16 +01:00
|
|
|
globals,
|
2024-12-19 20:25:01 +01:00
|
|
|
...
|
2024-12-21 20:57:16 +01:00
|
|
|
|
2024-12-19 20:25:01 +01:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
net
|
|
|
|
flip
|
|
|
|
mapAttrsToList
|
|
|
|
;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
environment.persistence."/persist".directories = [
|
|
|
|
{
|
|
|
|
directory = "/var/lib/private/kea";
|
|
|
|
mode = "0700";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
services.kea.dhcp4 = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
lease-database = {
|
|
|
|
name = "/var/lib/kea/dhcp4.leases";
|
|
|
|
persist = true;
|
|
|
|
type = "memfile";
|
|
|
|
};
|
|
|
|
valid-lifetime = 86400;
|
|
|
|
renew-timer = 3600;
|
|
|
|
interfaces-config = {
|
2024-12-23 17:03:10 +01:00
|
|
|
interfaces = flip mapAttrsToList globals.net.vlans (x: _: "lan-${x}");
|
2024-12-19 20:25:01 +01:00
|
|
|
};
|
2024-12-23 17:03:10 +01:00
|
|
|
subnet4 = flip mapAttrsToList globals.net.vlans (
|
|
|
|
name:
|
2025-01-07 21:23:06 +01:00
|
|
|
{
|
|
|
|
id,
|
|
|
|
cidrv4,
|
|
|
|
internet,
|
2025-01-09 13:58:51 +01:00
|
|
|
dns,
|
2025-01-07 21:23:06 +01:00
|
|
|
...
|
|
|
|
}:
|
2024-12-23 17:03:10 +01:00
|
|
|
rec {
|
2024-12-19 20:25:01 +01:00
|
|
|
inherit id;
|
|
|
|
interface = "lan-${name}";
|
2025-01-09 13:58:51 +01:00
|
|
|
subnet = cidrv4;
|
2024-12-19 20:25:01 +01:00
|
|
|
pools = [
|
|
|
|
{
|
|
|
|
pool = "${net.cidr.host 50 subnet} - ${net.cidr.host (-6) subnet}";
|
|
|
|
}
|
|
|
|
];
|
2025-01-07 21:23:06 +01:00
|
|
|
option-data =
|
2025-01-09 13:58:51 +01:00
|
|
|
lib.optional dns {
|
|
|
|
name = "domain-name-servers";
|
|
|
|
data = "${net.cidr.host globals.services.adguardhome.ip globals.net.vlans.services.cidrv4}";
|
|
|
|
}
|
2025-01-07 21:23:06 +01:00
|
|
|
++ lib.optional internet {
|
2024-12-19 20:25:01 +01:00
|
|
|
name = "routers";
|
|
|
|
data = "${net.cidr.host 1 subnet}";
|
2025-01-07 21:23:06 +01:00
|
|
|
};
|
2024-12-19 20:25:01 +01:00
|
|
|
reservations = [
|
2024-12-23 12:42:21 +01:00
|
|
|
{
|
|
|
|
# homematic
|
|
|
|
hw-address = "b8:27:eb:5d:ff:36";
|
|
|
|
ip-address = net.cidr.host 30 subnet;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# testberry
|
|
|
|
hw-address = "d8:3a:dd:dc:b6:6a";
|
|
|
|
ip-address = net.cidr.host 31 subnet;
|
|
|
|
}
|
2024-12-23 17:03:10 +01:00
|
|
|
{
|
|
|
|
# drucker
|
|
|
|
hw-address = "48:9e:bd:5c:31:ac";
|
|
|
|
ip-address = net.cidr.host 32 subnet;
|
|
|
|
}
|
2025-01-09 13:58:51 +01:00
|
|
|
{
|
|
|
|
# varta
|
|
|
|
hw-address = "00:0c:c6:06:7a:70";
|
|
|
|
ip-address = net.cidr.host 20 subnet;
|
|
|
|
}
|
2024-12-19 20:25:01 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-23 17:03:10 +01:00
|
|
|
systemd.services.kea-dhcp4-server.after = flip mapAttrsToList globals.net.vlans (
|
2024-12-21 20:57:16 +01:00
|
|
|
name: _: "sys-subsystem-net-devices-${utils.escapeSystemdPath "lan-${name}"}.device"
|
|
|
|
);
|
2024-12-19 20:25:01 +01:00
|
|
|
}
|