add tproxy/tun autostart option
This commit is contained in:
5 files changed
+182
-2
No files matched your search
@@ -11,8 +11,8 @@ The goal is to replace GUI clients like v2rayN and throne – you configure your
|
|||||||
## What it gives you
|
## What it gives you
|
||||||
|
|
||||||
- **SOCKS5/HTTP proxy** on `127.0.0.1:1080` by default – always running, always available to apps
|
- **SOCKS5/HTTP proxy** on `127.0.0.1:1080` by default – always running, always available to apps
|
||||||
- **Transparent proxy (TProxy)** – redirect all system traffic through sing-box without configuring each app; start/stop on demand
|
- **Transparent proxy (TProxy)** – redirect all system traffic through sing-box without configuring each app; start/stop on demand or autostart at boot
|
||||||
- **TUN mode** – full tunnel via a virtual network interface; useful when TProxy doesn't cover something
|
- **TUN mode** – full tunnel via a virtual network interface; useful when TProxy doesn't cover something, with optional boot-time autostart
|
||||||
- **Subscription URLs** – point at a v2rayN/Clash-format subscription endpoint; the module fetches, decodes, and imports all proxies automatically, with a periodic refresh timer
|
- **Subscription URLs** – point at a v2rayN/Clash-format subscription endpoint; the module fetches, decodes, and imports all proxies automatically, with a periodic refresh timer
|
||||||
- **Multiple outbounds** with automatic latency-based switching or manual selection
|
- **Multiple outbounds** with automatic latency-based switching or manual selection
|
||||||
- **Per-outbound routing** – route specific domains, IPs, or geo sets to specific servers
|
- **Per-outbound routing** – route specific domains, IPs, or geo sets to specific servers
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ services.proxy-suite = {
|
|||||||
subscriptionUpdateInterval = "1d";
|
subscriptionUpdateInterval = "1d";
|
||||||
subscriptions = [ ];
|
subscriptions = [ ];
|
||||||
tproxy = {
|
tproxy = {
|
||||||
|
autostart = false;
|
||||||
enable = false;
|
enable = false;
|
||||||
localSubnets = [
|
localSubnets = [
|
||||||
"192.168.0.0/16"
|
"192.168.0.0/16"
|
||||||
@@ -52,6 +53,7 @@ services.proxy-suite = {
|
|||||||
tproxyPort = 1081;
|
tproxyPort = 1081;
|
||||||
tun = {
|
tun = {
|
||||||
address = "172.19.0.1/30";
|
address = "172.19.0.1/30";
|
||||||
|
autostart = false;
|
||||||
enable = false;
|
enable = false;
|
||||||
interface = "singtun0";
|
interface = "singtun0";
|
||||||
mtu = 1400;
|
mtu = 1400;
|
||||||
@@ -1674,6 +1676,41 @@ false
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
*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\.tproxy\.autostart
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Whether to start proxy-suite-tproxy automatically during boot by
|
||||||
|
attaching it to multi-user\.target\.
|
||||||
|
Only relevant when singBox\.tproxy\.enable = true\.
|
||||||
|
Cannot be enabled together with singBox\.tun\.autostart\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
false
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*Example:*
|
*Example:*
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
@@ -1825,6 +1862,41 @@ string
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## services\.proxy-suite\.singBox\.tun\.autostart
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Whether to start proxy-suite-tun automatically during boot by
|
||||||
|
attaching it to multi-user\.target\.
|
||||||
|
Only relevant when singBox\.tun\.enable = true\.
|
||||||
|
Cannot be enabled together with singBox\.tproxy\.autostart\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
false
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
```nix
|
||||||
|
true
|
||||||
|
```
|
||||||
|
|
||||||
|
*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\.tun\.interface
|
## services\.proxy-suite\.singBox\.tun\.interface
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -491,6 +491,18 @@ in
|
|||||||
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)";
|
||||||
|
|
||||||
|
autostart = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to start proxy-suite-tun automatically during boot by
|
||||||
|
attaching it to multi-user.target.
|
||||||
|
Only relevant when singBox.tun.enable = true.
|
||||||
|
Cannot be enabled together with singBox.tproxy.autostart.
|
||||||
|
'';
|
||||||
|
example = true;
|
||||||
|
};
|
||||||
|
|
||||||
interface = mkOption {
|
interface = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "singtun0";
|
default = "singtun0";
|
||||||
@@ -525,6 +537,18 @@ in
|
|||||||
tproxy = {
|
tproxy = {
|
||||||
enable = mkEnableOption "TProxy mode service (opt-in, transparent proxy via nftables)";
|
enable = mkEnableOption "TProxy mode service (opt-in, transparent proxy via nftables)";
|
||||||
|
|
||||||
|
autostart = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to start proxy-suite-tproxy automatically during boot by
|
||||||
|
attaching it to multi-user.target.
|
||||||
|
Only relevant when singBox.tproxy.enable = true.
|
||||||
|
Cannot be enabled together with singBox.tun.autostart.
|
||||||
|
'';
|
||||||
|
example = true;
|
||||||
|
};
|
||||||
|
|
||||||
localSubnets = mkOption {
|
localSubnets = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ "192.168.0.0/16" ];
|
default = [ "192.168.0.0/16" ];
|
||||||
|
|||||||
@@ -420,6 +420,10 @@ in
|
|||||||
assertion = invalidRoutingTargets == [ ];
|
assertion = invalidRoutingTargets == [ ];
|
||||||
message = "proxy-suite: routing.rules reference unknown outbound tag(s): ${lib.concatStringsSep ", " invalidRoutingTargets}";
|
message = "proxy-suite: routing.rules reference unknown outbound tag(s): ${lib.concatStringsSep ", " invalidRoutingTargets}";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
assertion = !(sb.tproxy.enable && sb.tproxy.autostart && sb.tun.enable && sb.tun.autostart);
|
||||||
|
message = "proxy-suite: singBox.tproxy.autostart and singBox.tun.autostart cannot both be enabled at the same time";
|
||||||
|
}
|
||||||
{
|
{
|
||||||
assertion =
|
assertion =
|
||||||
!t.enable
|
!t.enable
|
||||||
@@ -484,6 +488,7 @@ in
|
|||||||
"network.target"
|
"network.target"
|
||||||
"proxy-suite-socks.service"
|
"proxy-suite-socks.service"
|
||||||
];
|
];
|
||||||
|
wantedBy = lib.optionals sb.tproxy.autostart [ "multi-user.target" ];
|
||||||
requires = [ "proxy-suite-socks.service" ];
|
requires = [ "proxy-suite-socks.service" ];
|
||||||
conflicts = [ "proxy-suite-tun.service" ];
|
conflicts = [ "proxy-suite-tun.service" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
@@ -510,6 +515,7 @@ in
|
|||||||
proxy-suite-tun = {
|
proxy-suite-tun = {
|
||||||
description = "sing-box TUN proxy client";
|
description = "sing-box TUN proxy client";
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
|
wantedBy = lib.optionals sb.tun.autostart [ "multi-user.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
conflicts = [ "proxy-suite-tproxy.service" ];
|
conflicts = [ "proxy-suite-tproxy.service" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
|||||||
@@ -178,6 +178,58 @@ let
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
tproxyManualFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.tproxy.enable = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
tproxyAutostartFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.tproxy = {
|
||||||
|
enable = true;
|
||||||
|
autostart = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
tunManualFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.tun.enable = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
tunAutostartFixture = evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox.tun = {
|
||||||
|
enable = true;
|
||||||
|
autostart = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
conflictingAutostartModes = forceEval (
|
||||||
|
(evalProxySuite [
|
||||||
|
baseModule
|
||||||
|
{
|
||||||
|
services.proxy-suite.singBox = {
|
||||||
|
tproxy = {
|
||||||
|
enable = true;
|
||||||
|
autostart = true;
|
||||||
|
};
|
||||||
|
tun = {
|
||||||
|
enable = true;
|
||||||
|
autostart = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]).config.system.build.toplevel.drvPath
|
||||||
|
);
|
||||||
|
|
||||||
routingOrFixture = evalProxySuite [
|
routingOrFixture = evalProxySuite [
|
||||||
{
|
{
|
||||||
system.stateVersion = "26.05";
|
system.stateVersion = "26.05";
|
||||||
@@ -680,6 +732,32 @@ let
|
|||||||
assert tproxyWithFirewall.config.networking.firewall.enable;
|
assert tproxyWithFirewall.config.networking.firewall.enable;
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
(
|
||||||
|
assert tproxyManualFixture.config.services.proxy-suite.singBox.tproxy.autostart == false;
|
||||||
|
assert tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".wantedBy == [ ];
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
assert
|
||||||
|
tproxyAutostartFixture.config.systemd.services."proxy-suite-tproxy".wantedBy
|
||||||
|
== [ "multi-user.target" ];
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
assert tunManualFixture.config.services.proxy-suite.singBox.tun.autostart == false;
|
||||||
|
assert tunManualFixture.config.systemd.services."proxy-suite-tun".wantedBy == [ ];
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
assert
|
||||||
|
tunAutostartFixture.config.systemd.services."proxy-suite-tun".wantedBy
|
||||||
|
== [ "multi-user.target" ];
|
||||||
|
true
|
||||||
|
)
|
||||||
|
(
|
||||||
|
assert conflictingAutostartModes.success == false;
|
||||||
|
true
|
||||||
|
)
|
||||||
(
|
(
|
||||||
assert builtins.length routingOrDomainRules == 1;
|
assert builtins.length routingOrDomainRules == 1;
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in new issue
Block a user