move userControl to root options

This commit is contained in:
FUFSoB committed 2026-04-15 11:07:46 +05:00
1 parent 8d4779481c
commit eeea6c161d
4 files changed
+261 -69

No files matched your search

+133 -46
View File
@@ -39,8 +39,6 @@ Update module option docs there instead of editing this file by hand.
- [enable](#services-proxy-suite-approuting-proxychains-enable)
- [proxyDns](#services-proxy-suite-approuting-proxychains-proxydns)
- [quiet](#services-proxy-suite-approuting-proxychains-quiet)
- userControl
- [group](#services-proxy-suite-approuting-usercontrol-group)
- singBox
- [enable](#services-proxy-suite-singbox-enable)
- [clashApiPort](#services-proxy-suite-singbox-clashapiport)
@@ -127,6 +125,12 @@ Update module option docs there instead of editing this file by hand.
- [enable](#services-proxy-suite-tray-enable)
- [autostart](#services-proxy-suite-tray-autostart)
- [pollInterval](#services-proxy-suite-tray-pollinterval)
- userControl
- global
- [enable](#services-proxy-suite-usercontrol-global-enable)
- [group](#services-proxy-suite-usercontrol-group)
- perApp
- [enable](#services-proxy-suite-usercontrol-perapp-enable)
- zapret
- [enable](#services-proxy-suite-zapret-enable)
- cidrExemption
@@ -190,9 +194,6 @@ services.proxy-suite = {
proxyDns = true;
quiet = true;
};
userControl = {
group = "proxy-suite";
};
};
enable = false;
singBox = {
@@ -276,6 +277,15 @@ services.proxy-suite = {
enable = false;
pollInterval = 5;
};
userControl = {
global = {
enable = true;
};
group = "proxy-suite";
perApp = {
enable = true;
};
};
zapret = {
cidrExemption = {
cidrs = [ ];
@@ -350,9 +360,6 @@ services.proxy-suite = {
proxyDns = true;
quiet = true;
};
userControl = {
group = "proxy-suite";
};
};
enable = true;
singBox = {
@@ -508,6 +515,15 @@ services.proxy-suite = {
enable = true;
pollInterval = 5;
};
userControl = {
global = {
enable = true;
};
group = "proxy-suite";
perApp = {
enable = true;
};
};
zapret = {
cidrExemption = {
cidrs = [
@@ -1395,42 +1411,6 @@ true
<a id="services-proxy-suite-approuting-usercontrol-group"></a>
## services\.proxy-suite\.appRouting\.userControl\.group
Local group allowed to start and stop app-routing backend units via
polkit\. Add desktop users who should be able to run
` proxy-ctl wrap ... ` for route = “tun”, route = “tproxy”, or
route = “zapret” profiles to this group\.
*Type:*
string matching the pattern ^\[a-z_]\[a-z0-9_-]\*$
*Default:*
```nix
"proxy-suite"
```
*Example:*
```nix
"proxy-suite"
```
*Declared by:*
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
<a id="services-proxy-suite-singbox-enable"></a>
## services\.proxy-suite\.singBox\.enable
@@ -4011,11 +3991,116 @@ signed integer
<a id="services-proxy-suite-usercontrol-global-enable"></a>
## services\.proxy-suite\.userControl\.global\.enable
Whether members of userControl\.group may manage global
proxy-suite units without password prompts via commands like
` proxy-ctl tun on|off `, ` proxy-ctl tproxy on|off `,
` proxy-ctl restart `, or ` proxy-ctl subscription update `\.
*Type:*
boolean
*Default:*
```nix
true
```
*Example:*
```nix
true
```
*Declared by:*
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
<a id="services-proxy-suite-usercontrol-group"></a>
## services\.proxy-suite\.userControl\.group
Local group allowed to use passwordless polkit-backed ` proxy-ctl `
commands when userControl\.global\.enable or userControl\.perApp\.enable
is turned on\.
*Type:*
string matching the pattern ^\[a-z_]\[a-z0-9_-]\*$
*Default:*
```nix
"proxy-suite"
```
*Example:*
```nix
"proxy-suite"
```
*Declared by:*
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
<a id="services-proxy-suite-usercontrol-perapp-enable"></a>
## services\.proxy-suite\.userControl\.perApp\.enable
Whether members of userControl\.group may start and stop the
app-scoped backend units used by ` proxy-ctl wrap ... ` for
route = “tun”, route = “tproxy”, or route = “zapret” profiles
without password prompts\.
*Type:*
boolean
*Default:*
```nix
true
```
*Example:*
```nix
true
```
*Declared by:*
- [modules/proxy-suite/options\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options.nix)
<a id="services-proxy-suite-zapret-enable"></a>
## services\.proxy-suite\.zapret\.enable
Whether to enable zapret DPI bypass\.
@@ -4189,6 +4274,8 @@ string
<a id="services-proxy-suite-zapret-hostlistrules"></a>
## services\.proxy-suite\.zapret\.hostlistRules
Additional named zapret hostlists with per-list DPI mitigation rules\.
Each entry generates hostlists/list-\<name>\.txt and can clone a built-in
zapret family, add custom NFQWS rule fragments, or both\.
+37 -13
View File
@@ -331,6 +331,43 @@ in
options.services.proxy-suite = {
enable = mkEnableOption "proxy suite (sing-box + zapret + tg-ws-proxy)";
userControl = {
group = mkOption {
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
default = "proxy-suite";
description = ''
Local group allowed to use passwordless polkit-backed `proxy-ctl`
commands when userControl.global.enable or userControl.perApp.enable
is turned on.
'';
example = "proxy-suite";
};
global.enable =
(mkEnableOption "passwordless proxy-ctl control over global proxy-suite units")
// {
default = true;
description = ''
Whether members of userControl.group may manage global
proxy-suite units without password prompts via commands like
`proxy-ctl tun on|off`, `proxy-ctl tproxy on|off`,
`proxy-ctl restart`, or `proxy-ctl subscription update`.
'';
};
perApp.enable =
(mkEnableOption "passwordless proxy-ctl control over per-app routing helpers")
// {
default = true;
description = ''
Whether members of userControl.group may start and stop the
app-scoped backend units used by `proxy-ctl wrap ...` for
route = "tun", route = "tproxy", or route = "zapret" profiles
without password prompts.
'';
};
};
singBox = {
enable = mkOption {
type = types.bool;
@@ -1034,19 +1071,6 @@ in
};
};
userControl = {
group = mkOption {
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
default = "proxy-suite";
description = ''
Local group allowed to start and stop app-routing backend units via
polkit. Add desktop users who should be able to run
`proxy-ctl wrap ...` for route = "tun", route = "tproxy", or
route = "zapret" profiles to this group.
'';
example = "proxy-suite";
};
};
};
zapret = {
+21 -9
View File
@@ -18,9 +18,24 @@ let
sb = cfg.singBox;
t = cfg.tgWsProxy;
ar = cfg.appRouting;
uc = cfg.userControl;
art = ar.backends.tun;
artp = ar.backends.tproxy;
arz = ar.backends.zapret;
userControlEnabled = uc.global.enable || uc.perApp.enable;
userControlPolkitRules =
lib.optionalString uc.perApp.enable ''
if (unit.indexOf("proxy-suite-app-") === 0) {
return polkit.Result.YES;
}
''
+ lib.optionalString uc.global.enable ''
if ((unit.indexOf("proxy-suite-") === 0 &&
unit.indexOf("proxy-suite-app-") !== 0) ||
unit === "zapret-discord-youtube.service") {
return polkit.Result.YES;
}
'';
builtinTags = [
"proxy"
"direct"
@@ -911,14 +926,14 @@ in
# nftables must be on for TProxy to work.
networking.nftables.enable = lib.mkIf (sb.tproxy.enable || art.enable || artp.enable || arz.enable) (lib.mkDefault true);
users.groups = lib.mkIf cfg.enable {
"${ar.userControl.group}" = { };
users.groups = lib.mkIf (cfg.enable && userControlEnabled) {
"${uc.group}" = { };
};
security.polkit.enable = lib.mkIf cfg.enable true;
security.polkit.extraConfig = lib.mkIf cfg.enable (lib.mkAfter ''
security.polkit.enable = lib.mkIf (cfg.enable && userControlEnabled) true;
security.polkit.extraConfig = lib.mkIf (cfg.enable && userControlEnabled) (lib.mkAfter ''
polkit.addRule(function(action, subject) {
if (!subject.isInGroup("${ar.userControl.group}")) {
if (!subject.isInGroup("${uc.group}")) {
return null;
}
@@ -927,10 +942,7 @@ in
}
var unit = action.lookup("unit");
if (unit.indexOf("proxy-suite-") === 0 ||
unit === "zapret-discord-youtube.service") {
return polkit.Result.YES;
}
${userControlPolkitRules}
return null;
});
+70 -1
View File
@@ -914,6 +914,45 @@ let
builtins.readFile "${appRoutingZapretBase}/init.d/sysv/custom.d/50-proxy-suite-custom.sh";
appRoutingTunPolkitConfig = appRoutingTunFixture.config.security.polkit.extraConfig;
userControlGlobalOnlyFixture = evalProxySuite [
baseModule
{
services.proxy-suite.userControl = {
global.enable = true;
perApp.enable = false;
};
}
];
userControlGlobalOnlyPolkitConfig = userControlGlobalOnlyFixture.config.security.polkit.extraConfig;
userControlPerAppOnlyFixture = evalProxySuite [
baseModule
{
services.proxy-suite = {
appRouting = {
enable = true;
createDefaultProfiles = true;
backends.tun.enable = true;
};
userControl = {
global.enable = false;
perApp.enable = true;
};
};
}
];
userControlPerAppOnlyPolkitConfig = userControlPerAppOnlyFixture.config.security.polkit.extraConfig;
userControlDisabledFixture = evalProxySuite [
baseModule
{
services.proxy-suite.userControl = {
global.enable = false;
perApp.enable = false;
};
}
];
appRoutingZapretWithoutEnable = forceEval (
(evalProxySuite [
baseModule
@@ -1710,13 +1749,43 @@ let
true
)
# -- appRouting: proxy-suite group polkit rule covers global proxy-ctl managed units --
# -- userControl: default polkit rule covers both per-app and global proxy-ctl managed units --
(
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-app-\") === 0" appRoutingTunPolkitConfig;
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" appRoutingTunPolkitConfig;
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-app-\") !== 0" appRoutingTunPolkitConfig;
assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\"" appRoutingTunPolkitConfig;
true
)
# -- userControl: global-only rule excludes per-app units --
(
assert userControlGlobalOnlyFixture.config.users.groups ? "proxy-suite";
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" userControlGlobalOnlyPolkitConfig;
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-app-\") !== 0" userControlGlobalOnlyPolkitConfig;
assert builtins.match ".*unit\\.indexOf\\(\"proxy-suite-app-\"\\) === 0.*" userControlGlobalOnlyPolkitConfig == null;
assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\"" userControlGlobalOnlyPolkitConfig;
true
)
# -- userControl: per-app-only rule covers app-scoped helpers only --
(
assert userControlPerAppOnlyFixture.config.users.groups ? "proxy-suite";
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-app-\") === 0" userControlPerAppOnlyPolkitConfig;
assert builtins.match ".*unit\\.indexOf\\(\"proxy-suite-app-\"\\) !== 0.*" userControlPerAppOnlyPolkitConfig == null;
assert builtins.match ".*unit === \"zapret-discord-youtube\\.service\".*" userControlPerAppOnlyPolkitConfig == null;
true
)
# -- userControl: disabling both scopes removes group and polkit wiring --
(
assert !(userControlDisabledFixture.config.users.groups ? "proxy-suite");
assert !userControlDisabledFixture.config.security.polkit.enable;
assert builtins.match ".*subject\\.isInGroup\\(\"proxy-suite\"\\).*" userControlDisabledFixture.config.security.polkit.extraConfig == null;
assert builtins.match ".*org\\.freedesktop\\.systemd1\\.manage-units.*" userControlDisabledFixture.config.security.polkit.extraConfig == null;
true
)
# -- appRouting: app TProxy helper installs socket cgroup mark rules --
(
assert pkgs.lib.hasInfix "socket cgroupv2" appRoutingTproxyUserStartScript;