commit 09dda84f5e0ed892a25de80eb8d719df12a1df03
parent 4a95153c29a334ff39afb256f966d98bb4b5dc24
Author: Katja (ctucx) <git@ctu.cx>
Date: Wed, 21 May 2025 13:05:04 +0200
parent 4a95153c29a334ff39afb256f966d98bb4b5dc24
Author: Katja (ctucx) <git@ctu.cx>
Date: Wed, 21 May 2025 13:05:04 +0200
config/nixos: add `dns` module
1 file changed, 56 insertions(+), 0 deletions(-)
diff --git a/config/nixos/dns.nix b/config/nixos/dns.nix @@ -0,0 +1,56 @@ +{ + inputs, + dnsNix, + povSelf, + config, + lib, + pkgs, + ... +}: +let + inherit (lib) types; + cfg = lib.getAttrFromPath povSelf config; + +in +{ + + options = { + enable = { + type = types.bool; + default = false; + }; + + # contains dns entries defined on the local host + zones = { + type = types.attrsOf dnsNix.types.subzone; + default = {}; + }; + + # contains dns entries defined on the local host and on remote hosts, merged together + allZones = { + type = types.attrsOf dnsNix.types.zone; + default = {}; + }; + + zoneFiles = { + type = types.attrsOf types.path; + readOnly = true; + default = ( + cfg.allZones + |> lib.mapAttrs (name: zone: toString (pkgs.writeTextFile { + name = "${name}.zone"; + text = dnsNix.types.zoneToString name (dnsNix.evalZone name zone); + })) + ); + }; + }; + + config = lib.mkIf cfg.enable { + # serve records defined in all host configs + dns.allZones = lib.mkMerge ( + inputs.self.nixosConfigurations + |> lib.mapAttrsToList (hostName: hostConfig: hostConfig.config.dns.zones) + ); + }; + +}