2022-06-19 15:04:46 +03:00
|
|
|
{ config, hosts, inputs, pkgs, tools, ... }:
|
2021-10-16 21:20:16 +03:00
|
|
|
# TODO: is this secure?
|
|
|
|
let
|
|
|
|
inherit (hosts.${config.networking.hostName}) interfaces;
|
2022-06-19 15:04:46 +03:00
|
|
|
inherit (tools.meta) domain;
|
|
|
|
dot = config.security.acme.certs."securedns.${domain}";
|
2021-10-16 21:20:16 +03:00
|
|
|
in {
|
|
|
|
imports = [ ./zones.nix ];
|
|
|
|
|
|
|
|
networking.firewall = {
|
2022-06-19 15:04:46 +03:00
|
|
|
allowedTCPPorts = [ 53 853 ];
|
|
|
|
allowedUDPPorts = [ 53 853 ];
|
2021-10-16 21:20:16 +03:00
|
|
|
};
|
|
|
|
|
2022-06-19 15:04:46 +03:00
|
|
|
systemd.services.coredns = {
|
|
|
|
after = [ "network-addresses-vstub.service" ];
|
|
|
|
serviceConfig.LoadCredential = [
|
|
|
|
"dot-cert.pem:${dot.directory}/fullchain.pem"
|
|
|
|
"dot-key.pem:${dot.directory}/key.pem"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
security.acme.certs."securedns.${domain}" = {
|
|
|
|
group = "nginx";
|
|
|
|
webroot = "/var/lib/acme/acme-challenge";
|
|
|
|
# using a different ACME provider because Android Private DNS is fucky
|
|
|
|
server = "https://api.buypass.com/acme/directory";
|
|
|
|
reloadServices = [
|
|
|
|
"coredns.service"
|
|
|
|
];
|
|
|
|
};
|
2021-10-16 21:20:16 +03:00
|
|
|
services.coredns = {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
|
|
|
. {
|
|
|
|
bind ${interfaces.vstub.addr}
|
2022-05-27 02:02:42 +03:00
|
|
|
hosts ${inputs.self.packages.${pkgs.system}.stevenblack-hosts} {
|
2021-10-16 21:20:16 +03:00
|
|
|
fallthrough
|
|
|
|
}
|
|
|
|
chaos "Private Void DNS" info@privatevoid.net
|
|
|
|
forward . 127.0.0.1
|
|
|
|
}
|
2022-06-19 15:04:46 +03:00
|
|
|
tls://.:853 {
|
|
|
|
bind ${interfaces.primary.addr}
|
|
|
|
tls {$CREDENTIALS_DIRECTORY}/dot-cert.pem {$CREDENTIALS_DIRECTORY}/dot-key.pem
|
|
|
|
hosts ${inputs.self.packages.${pkgs.system}.stevenblack-hosts} {
|
|
|
|
fallthrough
|
|
|
|
}
|
|
|
|
chaos "Private Void DNS" info@privatevoid.net
|
|
|
|
forward . ${interfaces.primary.addr}
|
|
|
|
}
|
2021-10-16 21:20:16 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.bind = {
|
|
|
|
enable = true;
|
|
|
|
# TODO: un-hardcode all ip addresses
|
|
|
|
listenOn = [ interfaces.primary.addr "127.0.0.1" ];
|
|
|
|
ipv4Only = true;
|
|
|
|
|
|
|
|
cacheNetworks = [ "10.0.0.0/8" ];
|
|
|
|
extraConfig = ''
|
|
|
|
acl "trusted" {
|
|
|
|
127.0.0.0/8;
|
|
|
|
::1/128;
|
|
|
|
${interfaces.vstub.addr}/32;
|
|
|
|
10.100.0.0/16;
|
|
|
|
10.10.0.0/16;
|
|
|
|
};
|
|
|
|
acl "publicservers" {
|
|
|
|
116.202.226.86/32;
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
extraOptions = ''
|
|
|
|
recursion yes;
|
2022-06-19 15:04:46 +03:00
|
|
|
allow-recursion { trusted; ${interfaces.primary.addr}/32; };
|
2021-10-16 21:20:16 +03:00
|
|
|
dnssec-validation no;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|