ctucx.git: dns.nix

fork of https://github.com/kirelagin/dns.nix

commit 32510ef6446a0c923946f4d84e7e430786e62872
parent 1bdd6305f64b6586ba289a7c422935f9d8cdd243
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Wed, 20 Mar 2019 14:01:06 +0100

combinators: Add host combinator
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dns/combinators.nix b/dns/combinators.nix
@@ -36,6 +36,10 @@ ttl = ttl: record: record // { inherit ttl; };
 # Templates/shortcuts
 #
 
+host = ipv4: ipv6:
+  lib.optionalAttrs (ipv4 != null) { A = [ipv4]; } //
+  lib.optionalAttrs (ipv6 != null) { AAAA = [ipv6]; };
+
 delegateTo = nameservers: {
   NS = map ns nameservers;
 };
diff --git a/example.nix b/example.nix
@@ -45,13 +45,17 @@ let
       }
     ];
 
-    subdomains = {
+    subdomains = rec {
       www.A = [ "203.0.113.4" ];
+      www2 = host "203.0.113.5" "4321:0:1:2:3:4:567:89bb";
+      www3 = host "203.0.113.6" null;
+      www4 = www3;
 
       staging = delegateTo [
         "ns1.another.com."
         "ns2.another.com."
       ];
+
       foo.subdomains.www.CNAME = [ "foo.test.com." ];
     };
   };