summaryrefslogtreecommitdiff
path: root/config/networking/services/dhcp.nix
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2024-05-19 20:24:50 +0200
committerquentin@aristote.fr <quentin@aristote.fr>2024-05-19 20:26:20 +0200
commit6c89b45eec2a7bfc21b2831118d3a5a05aa3b162 (patch)
tree64cdf5a0f5483653f9e87a814a4307a02847acc7 /config/networking/services/dhcp.nix
parent8255139178180e681873713ce3488e63c4e3d4b8 (diff)
networking: dhcp: add static ips
Diffstat (limited to 'config/networking/services/dhcp.nix')
-rw-r--r--config/networking/services/dhcp.nix59
1 files changed, 38 insertions, 21 deletions
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;
};
};