From d31677b549307770cc21231a44ab2125f85da79d Mon Sep 17 00:00:00 2001
From: lilly <li@lly.sh>
Date: Fri, 21 Feb 2025 21:15:48 +0100
Subject: [PATCH] configure auth-dns to use netbox-fetched data

---
 systems/auth-dns.noc.eh22.intern.nix       | 35 ++++++++++------------
 systems/sketchy-router.noc.eh22.intern.nix |  6 ++++
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/systems/auth-dns.noc.eh22.intern.nix b/systems/auth-dns.noc.eh22.intern.nix
index 1b83f39..1ccfcb2 100644
--- a/systems/auth-dns.noc.eh22.intern.nix
+++ b/systems/auth-dns.noc.eh22.intern.nix
@@ -1,26 +1,15 @@
 {
   pkgs,
+  lib,
   ...
 }:
 let
-  noc_eh22_internZone = ''
-    $ORIGIN noc.eh22.intern.
-    $TTL 3600
-
-    ; zone management
-    noc.eh22.intern.    IN SOA auth-dns.noc.eh22.intern. noc.eh22.esterhegg.eu. (
-      1       ; serial (automatically incremented by knot)
-      7200    ; refresh
-      3600    ; retry
-      3600000 ; expire
-      60      ; negative response caching ttl
-    )
-    @           IN  NS   auth-dns
-
-    ; A/AAAA records
-    proxmox     IN  A    10.31.210.248
-    auth-dns    IN  A    10.31.210.253
-  '';
+  zones = (
+    lib.attrsets.mapAttrs' (name: fileType: {
+      name = name;
+      value = ../data/zones/${name};
+    }) (builtins.readDir ../data/zones)
+  );
 
   knotConf = pkgs.writeText "knot.conf" ''
     server:
@@ -48,7 +37,15 @@ in
   # enable knot authorative dns server
   # ref: https://search.nüschtos.de/?query=services.knot
   #      https://www.knot-dns.cz/docs/3.4/html/configuration.html
-  environment.etc."knot/zones/noc.eh22.intern.zone".text = noc_eh22_internZone;
+  environment.etc = (
+    lib.attrsets.mapAttrs' (name: value: {
+      name = "knot/zones/noc.eh22.intern.zone";
+      value = {
+        source = value;
+      };
+    }) zones
+  );
+
   services.knot = {
     enable = true;
     settingsFile = knotConf;
diff --git a/systems/sketchy-router.noc.eh22.intern.nix b/systems/sketchy-router.noc.eh22.intern.nix
index 3617e67..feeba88 100644
--- a/systems/sketchy-router.noc.eh22.intern.nix
+++ b/systems/sketchy-router.noc.eh22.intern.nix
@@ -69,6 +69,12 @@
               id = 300;
               subnet = "10.20.25.0/24";
               pools = [ { pool = "10.20.25.100 - 10.20.25.254"; } ];
+              reservations = [
+                {
+                  hw-address = "bc:24:11:c1:8a:a4";
+                  ip-address = "10.20.25.3";
+                }
+              ];
             }
           ];
         }