From 43a4843551fb6773e1288c7ee1541e2411512d0d Mon Sep 17 00:00:00 2001 From: Rouven Seifert Date: Thu, 18 Apr 2024 19:49:40 +0200 Subject: [PATCH] DNS: autogenerate CNAMES from nginx config --- hosts/falkenstein/modules/dns/default.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hosts/falkenstein/modules/dns/default.nix b/hosts/falkenstein/modules/dns/default.nix index 520990e..6a3c289 100644 --- a/hosts/falkenstein/modules/dns/default.nix +++ b/hosts/falkenstein/modules/dns/default.nix @@ -2,7 +2,8 @@ let modulo = number: mod: (number - ((number / mod) * mod)); secondary = "185.181.104.96"; - zonefile = with dns.lib.combinators; pkgs.writeText "rfive.de.zone.txt" (dns.lib.toString "rfive.de" { + domain = config.networking.domain; + zonefile = with dns.lib.combinators; pkgs.writeText "rfive.de.zone.txt" (dns.lib.toString domain { TTL = 3600; SOA = { nameServer = "ns.rfive.de."; @@ -44,8 +45,8 @@ let _domainkey.subdomains.rspamd.TXT = [ "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDoirUMubro4nlmY6a8JMwK9QB2agAXiJzexDU/7ba6KCggONfoSTfUHlrM/XeM1GG/9oKpngApxDPP97adJuxc8/EELyo4HjTyYD8GBFZhg0AN7V8IPaJ1o5k6dGDk8ZLh41ZCnlAVWkhVSKs5pYtzkrlJIfUSzyuoe8nuFsVe3QIDAQAB" ]; } - (lib.attrsets.genAttrs [ "cache" "chat" "matrix" "seafile" "vault" ] (label: { CNAME = [ "nuc.rfive.de." ]; })) - (lib.attrsets.genAttrs [ "purge" "rspamd" "trucks" ] (label: { CNAME = [ "falkenstein.rfive.de." ]; })) + (lib.attrsets.genAttrs (map (name: builtins.substring 0 (builtins.stringLength name - (builtins.stringLength domain + 1)) name) (builtins.attrNames self.nixosConfigurations.nuc.config.services.nginx.virtualHosts)) (label: { CNAME = [ "nuc.rfive.de." ]; })) + (lib.attrsets.genAttrs (map (name: builtins.substring 0 (builtins.stringLength name - (builtins.stringLength domain + 1)) name) (builtins.attrNames self.nixosConfigurations.falkenstein.config.services.nginx.virtualHosts)) (label: { CNAME = [ "falkenstein.rfive.de." ]; })) ]; }); in