2 Commits

Author SHA1 Message Date
  Astro a9abf3d365 nixos-module/container/dns: create initial records in dynamic zones 1 month ago
  Astro 8bc0ce6e15 nixos-module/container/dns: allow underscores in dynamic hostnames 1 month ago
1 changed files with 30 additions and 2 deletions
  1. 30
    2
      nix/nixos-module/container/dns.nix

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

@@ -324,14 +324,19 @@ in
324 324
             algorithm hmac-sha256;
325 325
             secret "${inputs.zentralwerk-network-key.lib.dyndnsKey}";
326 326
           };
327
+
328
+          # allow underscores in dynamic hostnames
329
+          ${lib.concatMapStringsSep "\n" (type: ''
330
+            check-names ${type} ignore;
331
+          '') [ "master" "slave" "response" ]}
327 332
         '';
328 333
       });
329 334
 
330
-    systemd.services.dynamic-zones = {
335
+    systemd.services.create-dynamic-zones = {
336
+      description = "Creates dynamic zone files";
331 337
       requiredBy = [ "bind.service" ];
332 338
       before = [ "bind.service" ];
333 339
       serviceConfig.Type = "oneshot";
334
-      # TODO: initial records
335 340
       script = ''
336 341
         mkdir -p /var/db/bind
337 342
 
@@ -345,5 +350,28 @@ in
345 350
         )}
346 351
       '';
347 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
+    };
348 376
   };
349 377
 }

Loading…
Cancel
Save