blob: 4370136b7f68821eaf476fba505b73f64e8b47a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
{
config,
lib,
...
}: let
ifaces = config.personal.networking.interfaces;
dependencies =
builtins.concatMap (iface: ["${iface}-netdev.service" "network-addresses-${iface}.service"])
["wan" "iot" "guest"]; # not enp3s0 because it may come down for good reasons
in {
services.kea.dhcp4 = {
enable = true;
settings = let
subnets = with ifaces; lib.filterAttrs (_: builtins.hasAttr "subnet") ifaces.all;
in {
interfaces-config = {
interfaces = builtins.attrNames subnets;
service-sockets-max-retries = 20;
service-sockets-retry-wait-time = 5000;
};
lease-database = {
name = "/var/lib/kea/dhcp4.leases";
persist = true;
type = "memfile";
};
valid-lifetime = 600;
max-valid-lifetime = 7200;
option-data = [
{
name = "domain-name-servers";
data = lib.concatStringsSep ", " config.networking.nameservers;
}
{
name = "subnet-mask";
data = "255.255.255.0";
}
];
subnet4 =
lib.mapAttrsToList (interface: {
subnet,
machines,
...
}: {
subnet = "${subnet.prefix}.0/${builtins.toString subnet.prefixLength}";
id = lib.toInt (lib.removePrefix "192.168." subnet.prefix);
option-data = [
{
name = "broadcast-address";
data = "${subnet.prefix}.255";
}
{
name = "routers";
data = machines.self.ip;
}
];
inherit interface;
pools = [{pool = "${subnet.prefix}.10 - ${subnet.prefix}.99";}];
reservations =
lib.mapAttrsToList (_: {
ip,
mac,
}: {
hw-address = mac;
ip-address = ip;
})
(lib.filterAttrs (name: addresses: name != "self" && addresses ? mac && addresses ? ip) machines);
})
subnets;
};
};
systemd.services.kea-dhcp4-server = {
after = dependencies;
bindsTo = dependencies;
};
}
|