nix/container/Dns.nix

145 lines
5.1 KiB
Nix
Raw Normal View History

{
container,
pkgs,
lib,
config,
...
2024-10-21 20:34:09 +03:00
}:
let
cfg = config.container.module.dns;
in
{
options = {
container.module.dns = {
2024-10-21 20:34:09 +03:00
enable = lib.mkEnableOption "the DNS server.";
address = lib.mkOption {
default = "10.1.0.6";
2024-10-21 20:34:09 +03:00
type = lib.types.str;
};
2024-10-21 20:34:09 +03:00
port = lib.mkOption {
default = 53;
2024-10-21 20:34:09 +03:00
type = lib.types.int;
};
};
};
2024-06-09 23:35:53 +03:00
2024-10-21 20:34:09 +03:00
config = lib.mkIf cfg.enable {
containers.dns = container.mkContainer cfg {
config =
{ ... }:
container.mkContainerConfig cfg {
2024-10-14 04:51:19 +03:00
environment.systemPackages = [ pkgs.cloudflared ];
2024-06-09 23:35:53 +03:00
2024-10-21 20:34:09 +03:00
# systemd.services.cloudflared = {
# description = "Cloudflare DoH server.";
# enable = true;
# wantedBy = [ "multi-user.target" ];
# serviceConfig = {
# Type = "simple";
# ExecStart = "${lib.getExe pkgs.cloudflared} proxy-dns --port 5054";
# };
# };
2024-06-25 04:04:39 +03:00
services.blocky = {
enable = true;
2024-10-24 12:15:47 +03:00
# REF: https://0xerr0r.github.io/blocky/main/configuration/
settings = {
2024-10-21 20:34:09 +03:00
bootstrapDns = "tcp+udp:1.1.1.1";
2024-10-21 20:42:38 +03:00
connectIPVersion = "v4";
2024-10-21 20:34:09 +03:00
upstreams.groups = {
default = [ "https://dns.quad9.net/dns-query" ];
};
caching = {
maxItemsCount = 100000;
maxTime = "30m";
minTime = "5m";
prefetchExpires = "2h";
prefetchMaxItemsCount = 100000;
prefetchThreshold = 5;
prefetching = true;
};
blocking = {
2024-10-21 20:34:09 +03:00
blockTTL = "1m";
blockType = "zeroIP";
loading = {
2024-10-24 12:15:47 +03:00
refreshPeriod = "24h";
2024-10-21 20:34:09 +03:00
strategy = "blocking";
downloads = {
timeout = "5m";
attempts = 3;
cooldown = "10s";
};
};
# SRC: https://oisd.nl
# SRC: https://v.firebog.net
denylists = {
suspicious = [
"https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt"
2024-10-21 20:34:09 +03:00
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" # https://github.com/StevenBlack/hosts
"https://v.firebog.net/hosts/static/w3kbl.txt"
];
ads = [
2024-10-21 20:34:09 +03:00
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext"
"https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts"
"https://v.firebog.net/hosts/AdguardDNS.txt"
"https://v.firebog.net/hosts/Admiral.txt"
"https://v.firebog.net/hosts/Easylist.txt"
];
tracking = [
2024-10-21 20:34:09 +03:00
"https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt"
"https://v.firebog.net/hosts/Easyprivacy.txt"
"https://v.firebog.net/hosts/Prigent-Ads.txt"
];
malicious = [
2024-10-21 20:34:09 +03:00
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt"
"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt"
"https://phishing.army/download/phishing_army_blocklist_extended.txt"
"https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts"
2024-10-21 20:34:09 +03:00
"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt"
"https://urlhaus.abuse.ch/downloads/hostfile/"
2024-10-21 20:34:09 +03:00
"https://v.firebog.net/hosts/Prigent-Crypto.txt"
"https://v.firebog.net/hosts/Prigent-Malware.txt"
];
other = [
"https://big.oisd.nl/domainswild"
"https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser"
];
};
2024-10-21 20:34:09 +03:00
# allowlists = {
# other = [
# "/.*.vk.com/"
# ];
# };
clientGroupsBlock = {
default = [
"suspicious"
"ads"
"tracking"
"malicious"
"other"
];
};
};
customDNS = {
mapping =
let
2024-10-21 20:34:09 +03:00
block = host: { ${host} = "0.0.0.0"; };
in
{
# All subdomains to current host.
# ${config.container.domain} = config.container.host;
"voronind.com" = "10.0.0.1";
2024-10-21 20:34:09 +03:00
}
// block "gosuslugi.ru"
// block "rutube.ru"
// block "vk.com";
};
2024-10-21 20:34:09 +03:00
ports.dns = cfg.port;
# httpPort = "80";
};
};
};
};
};
2024-06-09 23:35:53 +03:00
}