summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/dns.nix77
1 files changed, 77 insertions, 0 deletions
diff --git a/modules/dns.nix b/modules/dns.nix
new file mode 100644
index 00000000..276e9f81
--- /dev/null
+++ b/modules/dns.nix
@@ -0,0 +1,77 @@
+{ config, lib, pkgs, ... }: {
+ options.hrm.dns.zones = lib.mkOption {
+ default = {};
+ description = ''
+ DNS zones, written as zone files for an authoritative server.
+ '';
+ type = lib.types.attrsOf (lib.types.submodule ({ config, name, ... }: {
+ options = {
+ ttl = lib.mkOption {
+ type = lib.types.ints.unsigned;
+ default = 60;
+ };
+ soa = {
+ nameserver = lib.mkOption {
+ type = lib.types.str;
+ };
+ email = lib.mkOption {
+ type = lib.types.str;
+ };
+ serial = lib.mkOption {
+ type = lib.types.ints.unsigned;
+ };
+ refresh = lib.mkOption {
+ type = lib.types.ints.between 3600 86400;
+ default = 3600;
+ };
+ retry = lib.mkOption {
+ type = lib.types.ints.unsigned;
+ default = 900;
+ };
+ expire = lib.mkOption {
+ type = lib.types.ints.between 604800 3600000;
+ default = 604800;
+ };
+ minimum = lib.mkOption {
+ type = lib.types.ints.between 180 86400;
+ default = 180;
+ };
+ };
+ records = lib.mkOption {
+ type = lib.types.attrsOf (lib.types.listOf lib.types.str);
+ default = {};
+ description = ''
+ Records by owner name, each written after its name in the zone
+ file, e.g. "MX 10 ne" or "3600 NS ns2".
+ '';
+ };
+ file = lib.mkOption {
+ type = lib.types.package;
+ readOnly = true;
+ };
+ };
+ config.file = pkgs.runCommand "${name}.zone" {
+ nativeBuildInputs = [ pkgs.knot-dns ];
+ preferLocalBuild = true;
+ passAsFile = [ "text" ];
+ text = lib.concatLines ([
+ "$TTL ${toString config.ttl}"
+ "@ SOA ${lib.concatStringsSep " " [
+ config.soa.nameserver
+ (lib.replaceStrings [ "@" ] [ "." ] config.soa.email + ".")
+ (toString config.soa.serial)
+ (toString config.soa.refresh)
+ (toString config.soa.retry)
+ (toString config.soa.expire)
+ (toString config.soa.minimum)
+ ]}"
+ ] ++ lib.concatLists (lib.mapAttrsToList
+ (owner: map (record: "${owner} ${record}"))
+ config.records));
+ } ''
+ kzonecheck --origin ${lib.escapeShellArg name} "$textPath"
+ cp "$textPath" "$out"
+ '';
+ }));
+ };
+}