2022-12-26 15:27:09 +01:00
|
|
|
|
{ config, pkgs, flat_hosts, ... }:
|
2021-11-23 14:26:40 +01:00
|
|
|
|
let
|
2022-09-10 15:10:01 +02:00
|
|
|
|
inherit (builtins) filter hasAttr;
|
2021-11-23 14:26:40 +01:00
|
|
|
|
hostToDhcp = { hostname, mac, ip, ... }: {
|
|
|
|
|
ethernetAddress = mac;
|
|
|
|
|
hostName = hostname;
|
|
|
|
|
ipAddress = ip;
|
|
|
|
|
};
|
2023-04-28 10:28:06 +02:00
|
|
|
|
hostToKea = {hostname, mac, ip, ...}: {
|
|
|
|
|
inherit hostname;
|
|
|
|
|
hw-address = mac;
|
|
|
|
|
ip-address = ip;
|
|
|
|
|
};
|
2022-07-30 23:35:52 +02:00
|
|
|
|
localDomain = config.networking.domain;
|
2022-12-26 15:27:09 +01:00
|
|
|
|
hosts =
|
|
|
|
|
filter (h: hasAttr "ip" h && hasAttr "mac" h && h.realm == localDomain)
|
|
|
|
|
flat_hosts;
|
2021-11-23 14:26:40 +01:00
|
|
|
|
in {
|
|
|
|
|
networking = {
|
|
|
|
|
defaultGateway = "10.42.42.1";
|
|
|
|
|
nameservers = [ "10.42.42.15" "10.42.42.16" ];
|
|
|
|
|
interfaces.eth0 = {
|
|
|
|
|
useDHCP = false; # It turns out the barber just doesn't shave
|
|
|
|
|
ipv4.addresses = [{
|
|
|
|
|
address = "10.42.42.3";
|
|
|
|
|
prefixLength = 23;
|
|
|
|
|
}];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# This value determines the NixOS release from which the default
|
|
|
|
|
# settings for stateful data, like file locations and database versions
|
|
|
|
|
# on your system were taken. It‘s perfectly fine and recommended to leave
|
|
|
|
|
# this value at the release version of the first install of this system.
|
|
|
|
|
# Before changing this value read the documentation for this option
|
|
|
|
|
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
|
|
|
|
system.stateVersion = "21.11"; # Did you read the comment?
|
|
|
|
|
|
|
|
|
|
# Additional packages
|
|
|
|
|
environment.systemPackages = with pkgs; [ ];
|
|
|
|
|
|
|
|
|
|
networking.firewall.allowedUDPPorts = [ 67 ];
|
|
|
|
|
|
|
|
|
|
services.dhcpd4 = {
|
|
|
|
|
enable = true;
|
|
|
|
|
extraConfig = ''
|
|
|
|
|
option subnet-mask 255.255.254.0;
|
|
|
|
|
option broadcast-address 10.42.43.255;
|
|
|
|
|
option routers 10.42.42.1;
|
|
|
|
|
option domain-name-servers 10.42.42.15, 10.42.42.16;
|
2022-07-30 23:35:52 +02:00
|
|
|
|
option domain-name "${localDomain}";
|
|
|
|
|
option domain-search "${localDomain}";
|
2021-11-23 14:26:40 +01:00
|
|
|
|
subnet 10.42.42.0 netmask 255.255.254.0 {
|
|
|
|
|
range 10.42.43.1 10.42.43.254;
|
|
|
|
|
}
|
|
|
|
|
'';
|
2022-12-26 15:27:09 +01:00
|
|
|
|
machines = map hostToDhcp hosts;
|
2021-11-23 14:26:40 +01:00
|
|
|
|
};
|
2023-04-28 10:28:06 +02:00
|
|
|
|
|
|
|
|
|
services.kea = {
|
|
|
|
|
dhcp4 = {
|
|
|
|
|
enable = false;
|
|
|
|
|
settings = {
|
|
|
|
|
authoritative = true;
|
|
|
|
|
valid-lifetime = 4000;
|
|
|
|
|
rebind-timer = 2000;
|
|
|
|
|
renew-timer = 1000;
|
|
|
|
|
|
|
|
|
|
interfaces-config.interfaces = [ "eth0" ];
|
|
|
|
|
|
|
|
|
|
lease-database = {
|
|
|
|
|
name = "/var/lib/kea/dhcp4.leases";
|
|
|
|
|
persist = true;
|
|
|
|
|
type = "memfile";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
option-data = [
|
|
|
|
|
{
|
|
|
|
|
name = "subnet-mask";
|
|
|
|
|
data = "255.255.254.0";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "broadcast-address";
|
|
|
|
|
data = "10.42.43.255";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "routers";
|
|
|
|
|
data = "10.42.42.1";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "domain-name-servers";
|
2023-04-28 10:37:37 +02:00
|
|
|
|
data = "10.42.42.15, 10.42.42.16";
|
2023-04-28 10:28:06 +02:00
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "domain-name";
|
|
|
|
|
data = "${localDomain}";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "domain-search";
|
|
|
|
|
data = "${localDomain}";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2023-04-28 10:37:37 +02:00
|
|
|
|
host-reservation-identifiers = [ "hw-address" ];
|
|
|
|
|
|
2023-04-28 10:28:06 +02:00
|
|
|
|
subnet4 = [{
|
|
|
|
|
id = 1;
|
|
|
|
|
pools = [{ pool = "10.42.43.1 - 10.42.43.254"; }];
|
|
|
|
|
subnet = "10.42.42.0/23";
|
2023-04-28 10:37:37 +02:00
|
|
|
|
reservations = map hostToKea hosts;
|
2023-04-28 10:28:06 +02:00
|
|
|
|
}];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2021-11-23 14:26:40 +01:00
|
|
|
|
}
|