make dns configurable

This commit is contained in:
FUFSoB committed 2026-04-13 17:26:48 +05:00
1 parent 5f45041e4c
commit 215958b367
5 files changed
+465 -12

No files matched your search

+12 -12
View File
@@ -11,6 +11,14 @@ let
sb = cfg.singBox;
direct = rules.direct;
mkDnsServer =
tag: upstream: detour: {
inherit tag detour;
type = upstream.type;
server = upstream.address;
server_port = upstream.port;
};
clashApiBlock = lib.optionalAttrs (sb.selection != "first") {
experimental = {
clash_api = {
@@ -21,20 +29,12 @@ let
dnsConfig = {
servers = [
{
tag = "remote";
type = "udp";
server = "1.1.1.1";
detour = "proxy";
}
{
tag = "local";
type = "udp";
server = "1.1.1.1";
(mkDnsServer "remote" sb.dns.remote "proxy")
(
# In TUN mode, routing DNS through direct can conflict with auto_redirect.
# In TProxy/mixed mode, direct is fine for local traffic.
detour = "direct";
}
mkDnsServer "local" sb.dns.local "direct"
)
];
rules =
lib.optional (builtins.elem "google" sb.routing.proxy.geosites) {
+78
View File
@@ -183,6 +183,40 @@ let
};
};
dnsUpstreamType = types.submodule {
options = {
type = mkOption {
type = types.enum [
"udp"
"tcp"
"tls"
];
default = "udp";
description = ''
sing-box DNS transport type for this upstream resolver.
'';
example = "tls";
};
address = mkOption {
type = types.strMatching ".+";
description = ''
Resolver address or hostname used for this DNS upstream.
'';
example = "1.1.1.1";
};
port = mkOption {
type = types.port;
default = 53;
description = ''
Destination port for this DNS upstream.
'';
example = 853;
};
};
};
zapretPresetType = types.enum [
"general"
"google"
@@ -488,6 +522,50 @@ in
example = true;
};
dns = {
local = mkOption {
type = dnsUpstreamType;
default = {
type = "udp";
address = "1.1.1.1";
port = 53;
};
description = ''
DNS upstream used for the built-in "local" resolver role.
This resolver is also used as sing-box route.default_domain_resolver.
The module keeps detour policy automatic: in mixed/TProxy mode,
"local" uses direct; in TUN mode, it is forced through the proxy to
avoid auto_redirect conflicts.
'';
example = {
type = "tcp";
address = "9.9.9.9";
port = 53;
};
};
remote = mkOption {
type = dnsUpstreamType;
default = {
type = "udp";
address = "1.1.1.1";
port = 53;
};
description = ''
DNS upstream used for the built-in "remote" resolver role.
This resolver always detours through the proxy and becomes the
generated dns.final target when singBox.proxyByDefault = true.
'';
example = {
type = "tls";
address = "1.1.1.1";
port = 853;
};
};
};
tun = {
enable = mkEnableOption "TUN mode service (opt-in, mutually exclusive with proxy-suite-tproxy)";