nameservers/recursive: Add option to block ads

This commit is contained in:
SebastianStork 2026-03-04 15:14:27 +01:00
parent 97b64f459e
commit fc6eafab59
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
3 changed files with 42 additions and 4 deletions

View file

@ -1,5 +1,7 @@
{
config,
inputs,
pkgs,
lib,
allHosts,
...
@ -8,6 +10,16 @@ let
cfg = config.custom.services.recursive-nameserver;
netCfg = config.custom.networking;
blocklist =
pkgs.runCommand "blocklist.conf" { } ''
echo "server:" > $out
cat ${inputs.blocklist}/hosts \
| grep '^0.0.0.0 ' \
| awk '$2 != "0.0.0.0" {print " local-zone: \"" $2 "\" refuse"}' \
>> $out
''
|> toString;
privateNameservers =
allHosts
|> lib.attrValues
@ -20,6 +32,7 @@ in
type = lib.types.port;
default = 53;
};
blockAds = lib.mkEnableOption "";
};
config = lib.mkIf cfg.enable (
@ -28,10 +41,13 @@ in
services = {
unbound = {
enable = true;
settings.server = {
interface = [ "${netCfg.overlay.address}@${toString cfg.port}" ];
access-control = [ "${toString netCfg.overlay.networkCidr} allow" ];
prefetch = true;
settings = {
server = {
interface = [ "${netCfg.overlay.address}@${toString cfg.port}" ];
access-control = [ "${toString netCfg.overlay.networkCidr} allow" ];
prefetch = true;
};
include-toplevel = lib.mkIf cfg.blockAds blocklist;
};
};