1
0
Fork 0
mirror of https://github.com/mdlayher/homelab.git synced 2024-12-15 17:50:54 +00:00
mdlayher-homelab/nixos/routnerr-2/dhcpd4.nix
Matt Layher b56aab6dd1
nixos/routnerr-2: more networkd
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2022-03-02 11:30:51 -05:00

63 lines
1.8 KiB
Nix

{ lib, ... }:
let
vars = import ./lib/vars.nix;
lans = with vars.interfaces; [ mgmt0 lan0 guest0 iot0 lab0 ];
in {
# Start only after systemd-networkd interface setup completes.
systemd.services.dhcpd4.unitConfig = {
After = lib.mkForce "network-online.target";
Requires = "network-online.target";
};
services.dhcpd4 = {
interfaces = lib.forEach lans (lan: toString lan.name);
enable = true;
machines = with vars.hosts;
lib.forEach (infra ++ servers) (host: {
hostName = host.name;
ethernetAddress = host.mac;
ipAddress = host.ipv4;
});
extraConfig = ''
ddns-update-style none;
default-lease-time 86400;
max-lease-time 86400;
${with vars.interfaces;
lib.concatMapStrings (ifi:
# Since dhcpd4 doesn't speak CIDR notation, trim off the final octet of
# the router's address for our "/24" prefix.
let
pfx = lib.removeSuffix ".1" ipv4;
ipv4 = ifi.ipv4;
in ''
subnet ${pfx}.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option broadcast-address ${pfx}.255;
option routers ${ipv4};
option domain-name-servers ${ipv4};
range ${pfx}.50 ${pfx}.240;
allow booting;
next-server ${ipv4};
option bootfile-name "netboot.xyz.kpxe";
${
let
domain = vars.domain;
# Configure additional options for the primary internal LAN.
in if ifi.internal_dns then ''
option domain-search "${domain}";
option domain-name "${domain}";
'' else
""
}
}
'') lans}
'';
};
}