ctucx.git: dns-nix

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

commit cefdf0989d9fe3e5697a3c45287e0c5fb8008fa8
parent 0ea992ab4f084e5a6729c2033a55b067ae22923e
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 10 Mar 2019 02:43:38 +0100

records: Add MX
5 files changed, 47 insertions(+), 0 deletions(-)
M
README.md
|
2
++
M
dns/combinators.nix
|
12
++++++++++++
A
dns/types/records/MX.nix
|
30
++++++++++++++++++++++++++++++
M
dns/types/records/default.nix
|
1
+
M
example.nix
|
2
++
diff --git a/README.md b/README.md
@@ -39,6 +39,8 @@ with dns.combinators; {
 
   CAA = letsEncrypt "admin@example.com";  # Common template combinators included
 
+  MX = mx.google;  # G Suite mail servers;
+
   TXT = [
     (with spf; strict [google])  # SPF: only allow gmail
   ];
diff --git a/dns/combinators.nix b/dns/combinators.nix
@@ -40,6 +40,18 @@ delegateTo = nameservers: {
   NS = map ns nameservers;
 };
 
+mx = rec {
+  mx = preference: exchange: { inherit preference exchange; };
+
+  google = map (ttl 3600) [
+    (mx 1  "aspmx.l.google.com.")
+    (mx 5  "alt1.aspmx.l.google.com.")
+    (mx 5  "alt2.aspmx.l.google.com.")
+    (mx 10 "alt3.aspmx.l.google.com.")
+    (mx 10 "alt4.aspmx.l.google.com.")
+  ];
+};
+
 letsEncrypt = email: [
   { issuerCritical = false;
     tag = "issue";
diff --git a/dns/types/records/MX.nix b/dns/types/records/MX.nix
@@ -0,0 +1,30 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "MX";
+  options = {
+    preference = mkOption {
+      type = types.ints.u16;
+      example = 10;
+      description = "The preference given to this RR among others at the same owner. Lower values are preferred";
+    };
+    exchange = mkOption {
+      type = types.str;
+      example = "smtp.example.com.";
+      description = "A <domain-name> which specifies a host willing to act as a mail exchange for the owner name";
+    };
+  };
+  dataToString = {preference, exchange, ...}:
+    "${toString preference} ${exchange}";
+}
diff --git a/dns/types/records/default.nix b/dns/types/records/default.nix
@@ -14,6 +14,7 @@ let
     "AAAA"
     "CAA"
     "CNAME"
+    "MX"
     "NS"
     "SOA"
     "TXT"
diff --git a/example.nix b/example.nix
@@ -29,6 +29,8 @@ let
       (aaaa "4321:0:1:2:3:4:567:89ab")
     ];
 
+    MX = mx.google;
+
     TXT = [
       (with spf; strict ["a:mail.example.com" google])
     ];