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
|
||||
|
||||
- **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
|
||||
- **TUN mode** – full tunnel via a virtual network interface; useful when TProxy doesn't cover something
|
||||
- **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, 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
|
||||
- **Multiple outbounds** with automatic latency-based switching or manual selection
|
||||
- **Per-outbound routing** – route specific domains, IPs, or geo sets to specific servers
|
||||
|
||||
@@ -44,6 +44,7 @@ services.proxy-suite = {
|
||||
subscriptionUpdateInterval = "1d";
|
||||
subscriptions = [ ];
|
||||
tproxy = {
|
||||
autostart = false;
|
||||
enable = false;
|
||||
localSubnets = [
|
||||
"192.168.0.0/16"
|
||||
@@ -52,6 +53,7 @@ services.proxy-suite = {
|
||||
tproxyPort = 1081;
|
||||
tun = {
|
||||
address = "172.19.0.1/30";
|
||||
autostart = false;
|
||||
enable = false;
|
||||
interface = "singtun0";
|
||||
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:*
|
||||
|
||||
```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
|
||||
|
||||
|
||||
|
||||
@@ -491,6 +491,18 @@ in
|
||||
tun = {
|
||||
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 {
|
||||
type = types.str;
|
||||
default = "singtun0";
|
||||
@@ -525,6 +537,18 @@ in
|
||||
tproxy = {
|
||||
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 {
|
||||
type = types.listOf types.str;
|
||||
default = [ "192.168.0.0/16" ];
|
||||
|
||||
@@ -420,6 +420,10 @@ in
|
||||
assertion = 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 =
|
||||
!t.enable
|
||||
@@ -484,6 +488,7 @@ in
|
||||
"network.target"
|
||||
"proxy-suite-socks.service"
|
||||
];
|
||||
wantedBy = lib.optionals sb.tproxy.autostart [ "multi-user.target" ];
|
||||
requires = [ "proxy-suite-socks.service" ];
|
||||
conflicts = [ "proxy-suite-tun.service" ];
|
||||
serviceConfig = {
|
||||
@@ -510,6 +515,7 @@ in
|
||||
proxy-suite-tun = {
|
||||
description = "sing-box TUN proxy client";
|
||||
after = [ "network-online.target" ];
|
||||
wantedBy = lib.optionals sb.tun.autostart [ "multi-user.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
conflicts = [ "proxy-suite-tproxy.service" ];
|
||||
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 [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
@@ -680,6 +732,32 @@ let
|
||||
assert tproxyWithFirewall.config.networking.firewall.enable;
|
||||
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;
|
||||
true
|
||||
|
||||
Reference in new issue
Block a user