2023-05-04 13:06:08 +02:00
{ config , flat_hosts , . . . }:
2021-11-23 14:26:40 +01:00
let
2022-09-10 15:10:01 +02:00
inherit ( builtins ) filter hasAttr ;
2023-04-29 19:48:00 +02:00
hostToKea = { hostname , mac , ip , . . . }: {
2023-04-28 10:28:06 +02:00
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 " i p " h && hasAttr " m a c " h && h . realm == localDomain )
2023-09-25 11:56:02 +02:00
flat_hosts ;
in
{
2021-11-23 14:26:40 +01:00
networking = {
defaultGateway = " 1 0 . 4 2 . 4 2 . 1 " ;
nameservers = [ " 1 0 . 4 2 . 4 2 . 1 5 " " 1 0 . 4 2 . 4 2 . 1 6 " ] ;
interfaces . eth0 = {
useDHCP = false ; # It turns out the barber just doesn't shave
ipv4 . addresses = [ {
address = " 1 0 . 4 2 . 4 2 . 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 = " 2 1 . 1 1 " ; # Did you read the comment?
networking . firewall . allowedUDPPorts = [ 67 ] ;
2024-01-02 10:22:52 +01:00
services . prometheus . exporters . kea = {
enable = false ;
openFirewall = true ;
user = " k e a " ;
controlSocketPaths = [ " / t m p / k e a - d h c p 4 . s o c k e t " ] ;
} ;
# To make sure the control socket is accesible
2023-05-05 13:21:53 +02:00
2023-04-29 19:48:00 +02:00
services . kea . dhcp4 = {
enable = true ;
settings = {
authoritative = true ;
valid-lifetime = 4000 ;
rebind-timer = 2000 ;
renew-timer = 1000 ;
2023-04-28 10:28:06 +02:00
2023-04-29 19:48:00 +02:00
interfaces-config . interfaces = [ " e t h 0 " ] ;
2023-04-28 10:28:06 +02:00
2024-01-02 10:22:52 +01:00
control-socket = {
socket-type = " u n i x " ;
socket-name = " / t m p / k e a - d h c p 4 . s o c k e t " ;
} ;
2023-11-10 22:53:33 +01:00
# failed to initialize Kea server: configuration error using file '/etc/kea/dhcp4-server.conf': cannot create socket lockfile, /run/kea/kea-dhcp4.socket.lock, : No such file or directory
2023-05-05 13:21:53 +02:00
2023-04-29 19:48:00 +02:00
lease-database = {
name = " / v a r / l i b / k e a / d h c p 4 . l e a s e s " ;
persist = true ;
type = " m e m f i l e " ;
} ;
2023-04-28 10:28:06 +02:00
2023-04-29 19:48:00 +02:00
option-data = [
{
name = " s u b n e t - m a s k " ;
data = " 2 5 5 . 2 5 5 . 2 5 4 . 0 " ;
}
{
name = " b r o a d c a s t - a d d r e s s " ;
data = " 1 0 . 4 2 . 4 3 . 2 5 5 " ;
}
{
name = " r o u t e r s " ;
data = " 1 0 . 4 2 . 4 2 . 1 " ;
}
{
name = " d o m a i n - n a m e - s e r v e r s " ;
data = " 1 0 . 4 2 . 4 2 . 1 5 , 1 0 . 4 2 . 4 2 . 1 6 " ;
}
{
name = " d o m a i n - n a m e " ;
data = localDomain ;
}
{
name = " d o m a i n - s e a r c h " ;
data = localDomain ;
}
] ;
2023-04-28 10:28:06 +02:00
2023-04-29 19:48:00 +02:00
host-reservation-identifiers = [ " h w - a d d r e s s " ] ;
2023-04-28 10:37:37 +02:00
2023-04-29 19:48:00 +02:00
subnet4 = [ {
id = 1 ;
pools = [ { pool = " 1 0 . 4 2 . 4 3 . 1 - 1 0 . 4 2 . 4 3 . 2 5 4 " ; } ] ;
subnet = " 1 0 . 4 2 . 4 2 . 0 / 2 3 " ;
reservations = map hostToKea hosts ;
} ] ;
2023-04-28 10:28:06 +02:00
} ;
} ;
2021-11-23 14:26:40 +01:00
}