make dns configurable
This commit is contained in:
5 files changed
+465
-12
No files matched your search
@@ -49,6 +49,24 @@ services.proxy-suite = {
|
|||||||
|
|
||||||
By default, `zapret` and `tgWsProxy` stay disabled until you enable them explicitly.
|
By default, `zapret` and `tgWsProxy` stay disabled until you enable them explicitly.
|
||||||
|
|
||||||
|
Example: override the built-in DNS upstreams while keeping proxy-suite's
|
||||||
|
default routing behavior:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
services.proxy-suite.singBox.dns = {
|
||||||
|
local = {
|
||||||
|
type = "tcp";
|
||||||
|
address = "9.9.9.9";
|
||||||
|
port = 53;
|
||||||
|
};
|
||||||
|
remote = {
|
||||||
|
type = "tls";
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 853;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|||||||
+276
@@ -10,6 +10,18 @@ services.proxy-suite = {
|
|||||||
enable = false;
|
enable = false;
|
||||||
singBox = {
|
singBox = {
|
||||||
clashApiPort = 9090;
|
clashApiPort = 9090;
|
||||||
|
dns = {
|
||||||
|
local = {
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 53;
|
||||||
|
type = "udp";
|
||||||
|
};
|
||||||
|
remote = {
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 53;
|
||||||
|
type = "udp";
|
||||||
|
};
|
||||||
|
};
|
||||||
enable = true;
|
enable = true;
|
||||||
fwmark = 1;
|
fwmark = 1;
|
||||||
listenAddress = "127.0.0.1";
|
listenAddress = "127.0.0.1";
|
||||||
@@ -188,6 +200,270 @@ Only used when selection is “selector” or “urltest”\. Ignored in
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.local
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
submodule
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 53;
|
||||||
|
type = "udp";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
address = "9.9.9.9";
|
||||||
|
port = 53;
|
||||||
|
type = "tcp";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.local\.address
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Resolver address or hostname used for this DNS upstream\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
string matching the pattern \.+
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"1.1.1.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.local\.port
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Destination port for this DNS upstream\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
16 bit unsigned integer; between 0 and 65535 (both inclusive)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
53
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
853
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.local\.type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sing-box DNS transport type for this upstream resolver\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
one of “udp”, “tcp”, “tls”
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"udp"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"tls"
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.remote
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
submodule
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 53;
|
||||||
|
type = "udp";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
address = "1.1.1.1";
|
||||||
|
port = 853;
|
||||||
|
type = "tls";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.remote\.address
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Resolver address or hostname used for this DNS upstream\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
string matching the pattern \.+
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"1.1.1.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.remote\.port
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Destination port for this DNS upstream\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
16 bit unsigned integer; between 0 and 65535 (both inclusive)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
53
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
853
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.dns\.remote\.type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sing-box DNS transport type for this upstream resolver\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
one of “udp”, “tcp”, “tls”
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"udp"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
"tls"
|
||||||
|
```
|
||||||
|
|
||||||
|
*Declared by:*
|
||||||
|
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## services\.proxy-suite\.singBox\.fwmark
|
## services\.proxy-suite\.singBox\.fwmark
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ let
|
|||||||
sb = cfg.singBox;
|
sb = cfg.singBox;
|
||||||
direct = rules.direct;
|
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") {
|
clashApiBlock = lib.optionalAttrs (sb.selection != "first") {
|
||||||
experimental = {
|
experimental = {
|
||||||
clash_api = {
|
clash_api = {
|
||||||
@@ -21,20 +29,12 @@ let
|
|||||||
|
|
||||||
dnsConfig = {
|
dnsConfig = {
|
||||||
servers = [
|
servers = [
|
||||||
{
|
(mkDnsServer "remote" sb.dns.remote "proxy")
|
||||||
tag = "remote";
|
(
|
||||||
type = "udp";
|
|
||||||
server = "1.1.1.1";
|
|
||||||
detour = "proxy";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
tag = "local";
|
|
||||||
type = "udp";
|
|
||||||
server = "1.1.1.1";
|
|
||||||
# In TUN mode, routing DNS through direct can conflict with auto_redirect.
|
# In TUN mode, routing DNS through direct can conflict with auto_redirect.
|
||||||
# In TProxy/mixed mode, direct is fine for local traffic.
|
# In TProxy/mixed mode, direct is fine for local traffic.
|
||||||
detour = "direct";
|
mkDnsServer "local" sb.dns.local "direct"
|
||||||
}
|
)
|
||||||
];
|
];
|
||||||
rules =
|
rules =
|
||||||
lib.optional (builtins.elem "google" sb.routing.proxy.geosites) {
|
lib.optional (builtins.elem "google" sb.routing.proxy.geosites) {
|
||||||
|
|||||||
@@ -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 [
|
zapretPresetType = types.enum [
|
||||||
"general"
|
"general"
|
||||||
"google"
|
"google"
|
||||||
@@ -488,6 +522,50 @@ in
|
|||||||
example = true;
|
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 = {
|
tun = {
|
||||||
enable = mkEnableOption "TUN mode service (opt-in, mutually exclusive with proxy-suite-tproxy)";
|
enable = mkEnableOption "TUN mode service (opt-in, mutually exclusive with proxy-suite-tproxy)";
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,17 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile configs.tproxyFile));
|
builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile configs.tproxyFile));
|
||||||
|
mkTunConfig =
|
||||||
|
fixture:
|
||||||
|
let
|
||||||
|
cfg = fixture.config.services.proxy-suite;
|
||||||
|
rules = mkRouting fixture;
|
||||||
|
configs = import ../modules/proxy-suite/config.nix {
|
||||||
|
lib = pkgs.lib;
|
||||||
|
inherit pkgs cfg rules;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile configs.tunFile));
|
||||||
hasDirectDomain =
|
hasDirectDomain =
|
||||||
rules: domain:
|
rules: domain:
|
||||||
builtins.any (
|
builtins.any (
|
||||||
@@ -55,6 +66,9 @@ let
|
|||||||
dnsHasRuleSet =
|
dnsHasRuleSet =
|
||||||
dnsRules: ruleSet:
|
dnsRules: ruleSet:
|
||||||
builtins.any (rule: (rule ? rule_set) && builtins.elem ruleSet rule.rule_set) dnsRules;
|
builtins.any (rule: (rule ? rule_set) && builtins.elem ruleSet rule.rule_set) dnsRules;
|
||||||
|
dnsServerByTag =
|
||||||
|
dnsConfig: tag:
|
||||||
|
builtins.head (builtins.filter (server: server.tag == tag) dnsConfig.dns.servers);
|
||||||
mkZapretBase =
|
mkZapretBase =
|
||||||
fixture:
|
fixture:
|
||||||
let
|
let
|
||||||
@@ -277,6 +291,31 @@ let
|
|||||||
];
|
];
|
||||||
ruExplicitConfig = mkTProxyConfig ruExplicitFixture;
|
ruExplicitConfig = mkTProxyConfig ruExplicitFixture;
|
||||||
|
|
||||||
|
dnsLocalOverrideFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.dns.local = {
|
||||||
|
type = "tcp";
|
||||||
|
address = "9.9.9.9";
|
||||||
|
port = 5353;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
dnsLocalOverrideConfig = mkTProxyConfig dnsLocalOverrideFixture;
|
||||||
|
|
||||||
|
dnsRemoteOverrideFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.dns.remote = {
|
||||||
|
type = "tls";
|
||||||
|
address = "1.0.0.1";
|
||||||
|
port = 853;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
dnsRemoteOverrideConfig = mkTProxyConfig dnsRemoteOverrideFixture;
|
||||||
|
tunDefaultConfig = mkTunConfig tunManualFixture;
|
||||||
|
|
||||||
zapretSyncFixture = evalProxySuite [
|
zapretSyncFixture = evalProxySuite [
|
||||||
baseModule
|
baseModule
|
||||||
{
|
{
|
||||||
@@ -782,6 +821,21 @@ let
|
|||||||
assert (builtins.head routingOrGeoIPRules).outbound == "proxy";
|
assert (builtins.head routingOrGeoIPRules).outbound == "proxy";
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
(
|
||||||
|
let
|
||||||
|
localDns = dnsServerByTag ruDefaultConfig "local";
|
||||||
|
remoteDns = dnsServerByTag ruDefaultConfig "remote";
|
||||||
|
in
|
||||||
|
assert localDns.type == "udp";
|
||||||
|
assert localDns.server == "1.1.1.1";
|
||||||
|
assert localDns.server_port == 53;
|
||||||
|
assert localDns.detour == "direct";
|
||||||
|
assert remoteDns.type == "udp";
|
||||||
|
assert remoteDns.server == "1.1.1.1";
|
||||||
|
assert remoteDns.server_port == 53;
|
||||||
|
assert remoteDns.detour == "proxy";
|
||||||
|
true
|
||||||
|
)
|
||||||
(
|
(
|
||||||
assert hasRuleSet ruDefaultRules "direct" "geosite-category-ru";
|
assert hasRuleSet ruDefaultRules "direct" "geosite-category-ru";
|
||||||
true
|
true
|
||||||
@@ -810,6 +864,33 @@ let
|
|||||||
assert dnsHasRuleSet ruExplicitConfig.dns.rules "geosite-category-ru";
|
assert dnsHasRuleSet ruExplicitConfig.dns.rules "geosite-category-ru";
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
(
|
||||||
|
let
|
||||||
|
localDns = dnsServerByTag dnsLocalOverrideConfig "local";
|
||||||
|
in
|
||||||
|
assert localDns.type == "tcp";
|
||||||
|
assert localDns.server == "9.9.9.9";
|
||||||
|
assert localDns.server_port == 5353;
|
||||||
|
assert localDns.detour == "direct";
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
let
|
||||||
|
remoteDns = dnsServerByTag dnsRemoteOverrideConfig "remote";
|
||||||
|
in
|
||||||
|
assert remoteDns.type == "tls";
|
||||||
|
assert remoteDns.server == "1.0.0.1";
|
||||||
|
assert remoteDns.server_port == 853;
|
||||||
|
assert remoteDns.detour == "proxy";
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
let
|
||||||
|
localDns = dnsServerByTag tunDefaultConfig "local";
|
||||||
|
in
|
||||||
|
assert localDns.detour == "proxy";
|
||||||
|
true
|
||||||
|
)
|
||||||
(
|
(
|
||||||
assert hasDirectDomain zapretSyncRules "discord.com";
|
assert hasDirectDomain zapretSyncRules "discord.com";
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in new issue
Block a user