2021-04-21 21:35:01 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
wgCfg = config.my.services.wireguard;
|
|
|
|
cfg = config.my.services.adblock;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.adblock = with lib; {
|
|
|
|
enable = mkEnableOption "Hosts-based adblock using unbound";
|
|
|
|
|
|
|
|
forwardAddresses = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [
|
|
|
|
"1.0.0.1@853#cloudflare-dns.com"
|
|
|
|
"1.1.1.1@853#cloudflare-dns.com"
|
|
|
|
];
|
|
|
|
example = [
|
|
|
|
"8.8.4.4"
|
|
|
|
"8.8.8.8"
|
|
|
|
];
|
|
|
|
description = "Which DNS servers to forward queries to";
|
|
|
|
};
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [
|
|
|
|
"0.0.0.0"
|
|
|
|
"::"
|
|
|
|
];
|
|
|
|
example = literalExample ''
|
|
|
|
[
|
|
|
|
"127.0.0.1"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = "Which addresses to listen on";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-04-22 19:40:27 +02:00
|
|
|
# Allow wireguard clients to connect to it
|
|
|
|
networking.firewall.interfaces."${wgCfg.iface}" = {
|
|
|
|
allowedUDPPorts = [ 53 ];
|
|
|
|
allowedTCPPorts = [ 53 ];
|
|
|
|
};
|
2021-04-21 21:35:01 +02:00
|
|
|
|
|
|
|
services.unbound = {
|
|
|
|
enable = true;
|
|
|
|
|
2021-05-20 17:31:04 +02:00
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
access-control = [
|
|
|
|
"127.0.0.0/24 allow"
|
|
|
|
"${wgCfg.net.v4.subnet}.0/${toString wgCfg.net.v4.mask} allow"
|
|
|
|
"${wgCfg.net.v6.subnet}::0/${toString wgCfg.net.v6.mask} allow"
|
|
|
|
];
|
2021-04-21 21:35:01 +02:00
|
|
|
|
2021-05-20 17:31:04 +02:00
|
|
|
interface = cfg.interfaces;
|
2021-04-21 21:35:01 +02:00
|
|
|
|
2021-05-20 17:31:04 +02:00
|
|
|
so-reuseport = true;
|
|
|
|
tls-cert-bundle = "/etc/ssl/certs/ca-certificates.crt";
|
|
|
|
tls-upstream = true;
|
2021-04-21 21:35:01 +02:00
|
|
|
|
2021-05-20 17:31:04 +02:00
|
|
|
include = "${pkgs.ambroisie.unbound-zones-adblock}/hosts";
|
|
|
|
};
|
|
|
|
|
|
|
|
forward-zone = [{
|
|
|
|
name = ".";
|
|
|
|
forward-addr = cfg.forwardAddresses;
|
|
|
|
}];
|
|
|
|
};
|
2021-04-21 21:35:01 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|