From 6c89b45eec2a7bfc21b2831118d3a5a05aa3b162 Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Sun, 19 May 2024 20:24:50 +0200 Subject: networking: dhcp: add static ips --- config/networking/services/dhcp.nix | 59 ++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'config/networking/services/dhcp.nix') diff --git a/config/networking/services/dhcp.nix b/config/networking/services/dhcp.nix index 1f2d06f..d27bbce 100644 --- a/config/networking/services/dhcp.nix +++ b/config/networking/services/dhcp.nix @@ -1,13 +1,17 @@ -{ config, ... }: - -let +{ + config, + lib, + ... +}: let nets = config.personal.networking.networks; - netdevServices = builtins.map (subnet: "${subnet.interface}-netdev.service") - (with nets; [ wan iot ]); + netdevServices = + builtins.map (subnet: "${subnet.interface}-netdev.service") + (with nets; [wan iot]); in { services.kea.dhcp4 = { enable = true; - settings = let subnets = with nets; [ wan iot eth0 ]; + settings = let + subnets = with nets; [wan iot eth0]; in { interfaces-config = { interfaces = builtins.map (network: network.interface) subnets; @@ -31,21 +35,34 @@ in { data = "255.255.255.0"; } ]; - subnet4 = builtins.map (network: { - subnet = "${network.subnet}.0/24"; - option-data = [ - { - name = "broadcast-address"; - data = "${network.subnet}.255"; - } - { - name = "routers"; - data = network.machines.self.address; - } - ]; - inherit (network) interface; - pools = [{ pool = "${network.subnet}.10 - ${network.subnet}.99"; }]; - }) subnets; + subnet4 = + builtins.map (network: { + subnet = "${network.subnet}.0/24"; + option-data = [ + { + name = "broadcast-address"; + data = "${network.subnet}.255"; + } + { + name = "routers"; + data = network.machines.self.ip; + } + ]; + inherit (network) interface; + pools = [{pool = "${network.subnet}.10 - ${network.subnet}.99";}]; + reservations = let + machines = builtins.attrValues (lib.filterAttrs (name: {mac, ...}: name != "self" && mac != null) network.machines); + in + builtins.map ({ + ip, + mac, + }: { + hw-address = mac; + ip-address = ip; + }) + machines; + }) + subnets; }; }; -- cgit v1.2.3