2023-03-05 23:00:18 +02:00
|
|
|
{ cluster, config, hosts, lib, tools, ... }:
|
2022-08-07 20:58:37 +03:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (hosts.${config.networking.hostName}) interfaces;
|
2023-03-05 23:00:18 +02:00
|
|
|
inherit (tools.meta) domain;
|
2022-08-07 20:58:37 +03:00
|
|
|
|
|
|
|
patroni = cluster.config.links.patroni-pg-access;
|
|
|
|
|
|
|
|
translateConfig = cfg: let
|
|
|
|
configList = lib.mapAttrsToList (n: v: "${n}=${v}") cfg;
|
|
|
|
in lib.concatStringsSep "\n" configList;
|
|
|
|
in {
|
2023-03-05 23:00:18 +02:00
|
|
|
links.localAuthoritativeDNS = {};
|
|
|
|
|
2022-08-07 20:58:37 +03:00
|
|
|
age.secrets = {
|
|
|
|
pdns-db-credentials = {
|
|
|
|
file = ./pdns-db-credentials.age;
|
|
|
|
mode = "0400";
|
|
|
|
owner = "pdns";
|
|
|
|
group = "pdns";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = [ 53 ];
|
|
|
|
allowedUDPPorts = [ 53 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.powerdns = {
|
|
|
|
enable = true;
|
|
|
|
extraConfig = translateConfig {
|
|
|
|
launch = "gpgsql";
|
2023-03-05 23:00:18 +02:00
|
|
|
local-address = config.links.localAuthoritativeDNS.tuple;
|
2022-08-07 20:58:37 +03:00
|
|
|
gpgsql-host = patroni.ipv4;
|
|
|
|
gpgsql-port = patroni.portStr;
|
|
|
|
gpgsql-dbname = "powerdns";
|
|
|
|
gpgsql-user = "powerdns";
|
|
|
|
gpgsql-extra-connection-parameters = "passfile=${config.age.secrets.pdns-db-credentials.path}";
|
|
|
|
version-string = "Private Void DNS";
|
|
|
|
};
|
|
|
|
};
|
2023-03-05 23:00:18 +02:00
|
|
|
|
|
|
|
services.coredns = {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
|
|
|
. {
|
|
|
|
bind ${interfaces.primary.addr}
|
|
|
|
chaos "Private Void DNS" info@privatevoid.net
|
|
|
|
cache {
|
|
|
|
success 4000 86400
|
|
|
|
denial 0
|
|
|
|
prefetch 3
|
|
|
|
serve_stale 86400s
|
|
|
|
}
|
2023-03-05 23:16:06 +02:00
|
|
|
forward service.eu-central.sd-magic.${domain} 127.0.0.1:8600
|
2023-03-06 01:49:44 +02:00
|
|
|
forward addr.eu-central.sd-magic.${domain} 127.0.0.1:8600
|
2023-03-05 23:00:18 +02:00
|
|
|
forward . ${config.links.localAuthoritativeDNS.tuple}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.coredns = {
|
|
|
|
after = [ "pdns.service" ];
|
|
|
|
};
|
2023-03-06 00:50:50 +02:00
|
|
|
|
|
|
|
consul.services.pdns = {
|
|
|
|
mode = "external";
|
2023-03-06 17:42:14 +02:00
|
|
|
definition = {
|
2023-03-06 00:50:50 +02:00
|
|
|
name = "authoritative-dns-backend";
|
|
|
|
address = config.links.localAuthoritativeDNS.ipv4;
|
|
|
|
port = config.links.localAuthoritativeDNS.port;
|
|
|
|
checks = lib.singleton {
|
|
|
|
interval = "60s";
|
|
|
|
tcp = config.links.localAuthoritativeDNS.tuple;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-08-07 20:58:37 +03:00
|
|
|
}
|