Browse Source

nixos-module/container/dns: create initial records in dynamic zones

master
Astro 1 month ago
parent
commit
a9abf3d365
1 changed files with 25 additions and 2 deletions
  1. 25
    2
      nix/nixos-module/container/dns.nix

+ 25
- 2
nix/nixos-module/container/dns.nix View File

@@ -332,11 +332,11 @@ in
332 332
         '';
333 333
       });
334 334
 
335
-    systemd.services.dynamic-zones = {
335
+    systemd.services.create-dynamic-zones = {
336
+      description = "Creates dynamic zone files";
336 337
       requiredBy = [ "bind.service" ];
337 338
       before = [ "bind.service" ];
338 339
       serviceConfig.Type = "oneshot";
339
-      # TODO: initial records
340 340
       script = ''
341 341
         mkdir -p /var/db/bind
342 342
 
@@ -350,5 +350,28 @@ in
350 350
         )}
351 351
       '';
352 352
     };
353
+    systemd.services.update-dynamic-zones = {
354
+      description = "Creates initial records in dynamic zone files";
355
+      requiredBy = [ "bind.service" ];
356
+      after = [ "bind.service" ];
357
+      serviceConfig.Type = "oneshot";
358
+      path = [ pkgs.dnsutils ];
359
+      script = ''
360
+        ${lib.concatMapStrings (zone: ''
361
+          nsupdate -y "hmac-sha256:dyndns:${inputs.zentralwerk-network-key.lib.dyndnsKey}" <<EOF
362
+          server localhost
363
+
364
+          ${lib.concatMapStringsSep "\n" ({ name, type, data }: ''
365
+            delete ${name}.${zone.name}. IN ${type}
366
+            add ${name}.${zone.name}. 3600 IN ${type} ${data}
367
+          '') zone.records}
368
+
369
+          send
370
+          EOF
371
+        '') (
372
+          builtins.filter ({ dynamic, ... }: dynamic) config.site.dns.localZones
373
+        )}
374
+      '';
375
+    };
353 376
   };
354 377
 }

Loading…
Cancel
Save