forked from zentralwerk/network
81 lines
2.6 KiB
Nix
81 lines
2.6 KiB
Nix
# ISC DHCP/IPv4 server configuration
|
|
{ hostName, inputs, config, lib, ... }:
|
|
|
|
let
|
|
dhcpNets =
|
|
lib.filterAttrs (_: { dhcp, ... }:
|
|
dhcp != null &&
|
|
dhcp.server == hostName
|
|
) config.site.net;
|
|
|
|
enabled = builtins.length (builtins.attrNames dhcpNets) > 0;
|
|
in
|
|
{
|
|
services.dhcpd4 = lib.optionalAttrs enabled {
|
|
enable = true;
|
|
|
|
interfaces = builtins.attrNames dhcpNets;
|
|
|
|
extraConfig = ''
|
|
${builtins.concatStringsSep "\n" (
|
|
builtins.attrValues (
|
|
builtins.mapAttrs (net: { dhcp, subnet4Net, subnet4Len, domainName, ...}:
|
|
''
|
|
ddns-update-style standard;
|
|
key dyndns {
|
|
algorithm hmac-sha256;
|
|
secret ${inputs.zentralwerk-network-key.lib.dyndnsKey};
|
|
};
|
|
zone ${domainName}. {
|
|
primary ${config.site.net.serv.hosts4.dns};
|
|
primary6 ${config.site.net.serv.hosts6.dn42.dns};
|
|
key dyndns;
|
|
}
|
|
${lib.concatMapStrings ({ name, dynamic, ... }:
|
|
lib.optionalString (
|
|
dynamic &&
|
|
lib.hasSuffix ".in-addr.arpa" name
|
|
) ''
|
|
zone ${name}. {
|
|
primary ${config.site.net.serv.hosts4.dns};
|
|
primary6 ${config.site.net.serv.hosts6.dn42.dns};
|
|
key dyndns;
|
|
}
|
|
''
|
|
) config.site.dns.localZones}
|
|
|
|
group {
|
|
default-lease-time ${toString dhcp.time};
|
|
max-lease-time ${toString dhcp.max-time};
|
|
option routers ${config.site.net.${net}.hosts4.${builtins.replaceStrings [".${net}"] [""] dhcp.router}};
|
|
option domain-name "${domainName}";
|
|
option domain-name-servers 172.20.73.8, 9.9.9.9;
|
|
ddns-domainname "${domainName}";
|
|
|
|
subnet ${subnet4Net} netmask ${lib.netmasks.${toString subnet4Len}} {
|
|
range ${dhcp.start} ${dhcp.end};
|
|
}
|
|
|
|
update-static-leases on;
|
|
|
|
${builtins.concatStringsSep "\n" (
|
|
builtins.attrValues (
|
|
builtins.mapAttrs (addr: hwaddr:
|
|
''
|
|
host ${addr} {
|
|
hardware ethernet ${hwaddr};
|
|
fixed-address ${addr};
|
|
}
|
|
''
|
|
) dhcp.fixed-hosts
|
|
)
|
|
)}
|
|
}
|
|
''
|
|
) dhcpNets
|
|
)
|
|
)}
|
|
'';
|
|
};
|
|
}
|