refactor: remove duplication

This commit is contained in:
FUFSoB committed 2026-09-18 21:39:18 +05:00
1 parent f7036f6075
commit 8a4ba2db6a
109 files changed
+2206 -3078

No files matched your search

+2 -5
View File
@@ -27,8 +27,9 @@
xkcdpass, xkcdpass,
}: }:
writeShellApplication { import ./script.nix { inherit lib writeShellApplication; } {
name = "proxy-suite-install"; name = "proxy-suite-install";
script = ./installer.sh;
runtimeInputs = [ runtimeInputs = [
coreutils coreutils
curl curl
@@ -56,8 +57,4 @@ writeShellApplication {
PSI_FLAKE_SRC = "${flakeSource}"; PSI_FLAKE_SRC = "${flakeSource}";
PSI_STATE_VERSION = stateVersion; PSI_STATE_VERSION = stateVersion;
}; };
text = lib.concatStringsSep "\n" [
(builtins.readFile ./net-lib.sh)
(builtins.readFile ./installer.sh)
];
} }
+2 -5
View File
@@ -14,8 +14,9 @@
systemd, systemd,
}: }:
writeShellApplication { import ./script.nix { inherit lib writeShellApplication; } {
name = "proxy-suite-net"; name = "proxy-suite-net";
script = ./net-rescue.sh;
runtimeInputs = [ runtimeInputs = [
coreutils coreutils
curl curl
@@ -27,8 +28,4 @@ writeShellApplication {
iputils iputils
systemd systemd
]; ];
text = lib.concatStringsSep "\n" [
(builtins.readFile ./net-lib.sh)
(builtins.readFile ./net-rescue.sh)
];
} }
+16
View File
@@ -0,0 +1,16 @@
# The console helpers are net-lib.sh plus one front end, wrapped with the tools they call.
{ lib, writeShellApplication }:
{
name,
script,
runtimeInputs,
runtimeEnv ? { },
}:
writeShellApplication {
inherit name runtimeInputs runtimeEnv;
text = lib.concatStringsSep "\n" [
(builtins.readFile ./net-lib.sh)
(builtins.readFile script)
];
}
+1 -1
View File
@@ -321,7 +321,7 @@ in
services.getty.helpLine = '' services.getty.helpLine = ''
proxy-suite server ''${certName}. Share links (as ''${cfg.adminUser}): proxy-suite server ${certName}. Share links (as ${cfg.adminUser}):
proxy-ctl inbounds link vless-reality --qr (or vless-tls, vless-ws) proxy-ctl inbounds link vless-reality --qr (or vless-tls, vless-ws)
'' ''
+ lib.optionalString cfg.onion.enable " proxy-ctl inbounds link vless-reality --onion --qr (through Tor)\n" + lib.optionalString cfg.onion.enable " proxy-ctl inbounds link vless-reality --onion --qr (through Tor)\n"
+4 -17
View File
@@ -23,13 +23,10 @@ let
lanListeners = builtins.filter (listener: listener.mode == "lan") listeners; lanListeners = builtins.filter (listener: listener.mode == "lan") listeners;
lanIPv6 = lib.any (listener: listener.subnet6 != null) lanListeners; lanIPv6 = lib.any (listener: listener.subnet6 != null) lanListeners;
scriptsDir = builtins.path { scriptsDir = import ./lib/scripts-dir.nix { inherit lib; };
name = "proxy-suite-scripts";
path = ../../scripts;
};
python3 = "${pkgs.python3}/bin/python3"; python3 = "${pkgs.python3}/bin/python3";
awg = "${awgCfg.toolsPackage}/bin/awg"; awg = "${awgCfg.toolsPackage}/bin/awg";
awgQuick = "${awgCfg.toolsPackage}/bin/awg-quick"; awgCommon = import ./awg-common.nix { inherit lib pkgs awgCfg; };
# Diverted packets are delivered locally; only "lan" listeners forward. # Diverted packets are delivered locally; only "lan" listeners forward.
sysctl = sysctl =
@@ -128,9 +125,7 @@ let
set -Eeuo pipefail set -Eeuo pipefail
trap ${stop} ERR trap ${stop} ERR
${lib.optionalString (awgCfg.kernelModulePackage != null) '' ${awgCommon.modprobe}
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
''}
${stop} ${stop}
@@ -139,15 +134,7 @@ let
> "$RUNTIME_DIRECTORY/interfaces" > "$RUNTIME_DIRECTORY/interfaces"
while read -r _interface implementation config; do while read -r _interface implementation config; do
# The 3.1 kernel module drops RandomTrailers packets with ranged H1-H3; userspace does not. ${awgCommon.awgQuickUp "$implementation" "\"$config\""}
if [[ "$implementation" == userspace ]]; then
WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION=1 \
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgQuick} up "$config"
else
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgQuick} up "$config"
fi
done < "$RUNTIME_DIRECTORY/interfaces" done < "$RUNTIME_DIRECTORY/interfaces"
${lib.concatStrings ( ${lib.concatStrings (
+4 -19
View File
@@ -81,12 +81,8 @@ let
// source profile // source profile
) )
); );
configTool = "${ configTool = "${import ./lib/scripts-dir.nix { inherit lib; }}/amneziawg_config.py";
builtins.path { awgCommon = import ./awg-common.nix { inherit lib pkgs awgCfg; };
name = "proxy-suite-scripts";
path = ../../scripts;
}
}/amneziawg_config.py";
runtimeDir = name: "/run/${serviceName name}"; runtimeDir = name: "/run/${serviceName name}";
runtimeConfig = name: profile: "${runtimeDir name}/${profile.interfaceName}.conf"; runtimeConfig = name: profile: "${runtimeDir name}/${profile.interfaceName}.conf";
# Keep proxy backend sockets (proxyMark) out of AWG's default-route table. # Keep proxy backend sockets (proxyMark) out of AWG's default-route table.
@@ -204,22 +200,11 @@ let
} }
trap cleanup ERR trap cleanup ERR
${lib.optionalString (awgCfg.kernelModulePackage != null) '' ${awgCommon.modprobe}
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
''}
read -r implementation probe _ < <(${pkgs.python3}/bin/python3 ${configTool} \ read -r implementation probe _ < <(${pkgs.python3}/bin/python3 ${configTool} \
--inspect ${lib.escapeShellArg configPath}) --inspect ${lib.escapeShellArg configPath})
# The 3.1 kernel module dropped RandomTrailers packets with ranged H1-H3 (seen on 20260812); ${awgCommon.awgQuickUp "$implementation" (lib.escapeShellArg configPath)}
# userspace carries the fix.
if [[ "$implementation" == userspace ]]; then
WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION=1 \
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgCfg.toolsPackage}/bin/awg-quick up ${lib.escapeShellArg configPath}
else
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgCfg.toolsPackage}/bin/awg-quick up ${lib.escapeShellArg configPath}
fi
${mkHandshakeHelpers profile} ${mkHandshakeHelpers profile}
# A handshake is retried every 5 seconds: each retry after the first gets a new port. # A handshake is retried every 5 seconds: each retry after the first gets a new port.
+62
View File
@@ -0,0 +1,62 @@
# Routing rules → generated configs → nftables rule files → service context: the wiring the
# host-neutral module does at evaluation time, in one place so the docs generator and the
# checks assemble it exactly as the running system does.
{
lib,
pkgs,
cfg,
packages,
zapret,
}:
let
rules = import ./rules.nix {
inherit
lib
pkgs
cfg
zapret
;
};
configs = import ./config.nix {
inherit
lib
pkgs
cfg
rules
;
};
nftr = import ./nftables.nix { inherit lib pkgs cfg; };
context = import ./service/context.nix {
inherit
lib
pkgs
packages
cfg
;
inherit (configs)
tproxyFile
tunFile
perAppTunFile
routeModeRulesFile
proxyInboundsFile
proxyInboundsSpecFile
;
inherit (nftr)
perAppTunChainFile
perAppTproxyRulesFile
perAppZapretRulesFile
nftablesRulesFile
ip
nft
;
};
in
{
inherit
rules
configs
nftr
context
;
inherit (context) derived;
}
+27
View File
@@ -0,0 +1,27 @@
# Shared AmneziaWG plumbing: bringing an interface up the way both the client profiles
# (./amnezia-wg.nix) and the server listeners (./amnezia-wg-inbounds.nix) need it.
{
lib,
pkgs,
awgCfg,
}:
{
# The kernel module is optional; userspace works without it.
modprobe = lib.optionalString (awgCfg.kernelModulePackage != null) ''
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
'';
# `implementation` is a shell word holding "userspace" or "kernel", `config` the .conf path.
# The 3.1 kernel module dropped RandomTrailers packets with ranged H1-H3 (seen on 20260812);
# userspace carries the fix, so a profile that needs it asks for userspace by name.
awgQuickUp = implementation: config: ''
if [[ "${implementation}" == userspace ]]; then
WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION=1 \
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgCfg.toolsPackage}/bin/awg-quick up ${config}
else
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
${awgCfg.toolsPackage}/bin/awg-quick up ${config}
fi
'';
}
@@ -14,17 +14,7 @@ let
proxyInboundsResolveInSingBox proxyInboundsResolveInSingBox
; ;
localProxyAddress = localProxyAddress = derived.localProxy.host;
if
builtins.elem proxyCfg.listener.address [
"0.0.0.0"
"::"
""
]
then
"127.0.0.1"
else
proxyCfg.listener.address;
# The client stack's SOCKS listener; credentials are injected at start. # The client stack's SOCKS listener; credentials are injected at start.
localProxyOutbound = lib.optional proxyInboundsNeedLocalProxy { localProxyOutbound = lib.optional proxyInboundsNeedLocalProxy {
+13 -43
View File
@@ -18,8 +18,16 @@
let let
cfg = config.services.proxy-suite; cfg = config.services.proxy-suite;
packages = import ../../pkgs/default.nix { inherit pkgs; }; packages = import ../../pkgs/default.nix { inherit pkgs; };
nftr = import ./nftables.nix { inherit lib pkgs cfg; }; assembly = import ./assembly.nix {
derived = import ./derived.nix { inherit lib cfg; }; inherit
lib
pkgs
cfg
packages
zapret
;
};
inherit (assembly) nftr derived;
in in
{ {
imports = [ imports = [
@@ -44,48 +52,10 @@ in
} }
(lib.mkIf cfg.enable ( (lib.mkIf cfg.enable (
let
rules = import ./rules.nix {
inherit
lib
pkgs
cfg
zapret
;
};
configs = import ./config.nix {
inherit
lib
pkgs
cfg
rules
;
};
in
lib.mkMerge [ lib.mkMerge [
(import ./service { (import ./service {
inherit inherit lib pkgs cfg;
lib inherit (assembly) context;
pkgs
packages
cfg
;
inherit (configs)
tproxyFile
tunFile
perAppTunFile
routeModeRulesFile
proxyInboundsFile
proxyInboundsSpecFile
;
inherit (nftr)
nftablesRulesFile
perAppTproxyRulesFile
perAppZapretRulesFile
perAppTunChainFile
ip
nft
;
}) })
(lib.mkIf (lib.mkIf
@@ -176,7 +146,7 @@ in
cfg cfg
derived derived
; ;
inherit (configs) proxyInboundsSpecFile; inherit (assembly.configs) proxyInboundsSpecFile;
inherit (nftr) reservedIpBlock ip nft; inherit (nftr) reservedIpBlock ip nft;
} }
)) ))
+24 -5
View File
@@ -18,7 +18,6 @@ let
singBoxEnabled = proxyEnabled && proxyCfg.backend != "xray"; singBoxEnabled = proxyEnabled && proxyCfg.backend != "xray";
xrayEnabled = proxyEnabled && proxyCfg.backend != "sing-box"; xrayEnabled = proxyEnabled && proxyCfg.backend != "sing-box";
hybridEnabled = proxyEnabled && proxyCfg.backend == "hybrid"; hybridEnabled = proxyEnabled && proxyCfg.backend == "hybrid";
pureSingBoxEnabled = proxyEnabled && proxyCfg.backend == "sing-box";
pureXrayEnabled = proxyEnabled && proxyCfg.backend == "xray"; pureXrayEnabled = proxyEnabled && proxyCfg.backend == "xray";
activeBackend = if proxyEnabled then proxyCfg.backend else null; activeBackend = if proxyEnabled then proxyCfg.backend else null;
perAppRoutingCfg = cfg.perAppRouting; perAppRoutingCfg = cfg.perAppRouting;
@@ -36,6 +35,29 @@ let
# Only sing-box dials SSH natively; XRay and standalone tunnels use the OpenSSH unit. # Only sing-box dials SSH natively; XRay and standalone tunnels use the OpenSSH unit.
sshProxyNativeOutbound = sshProxyOutboundEnabled && !pureXrayEnabled; sshProxyNativeOutbound = sshProxyOutboundEnabled && !pureXrayEnabled;
sshProxyUnitEnabled = sshProxyCfg.enable && !sshProxyNativeOutbound; sshProxyUnitEnabled = sshProxyCfg.enable && !sshProxyNativeOutbound;
# The local proxy as the other services dial it: a wildcard listener is reached on loopback.
# (The secret itself stays with whoever needs it on disk: derived.nix has no pkgs.)
localProxy =
let
auth = proxyCfg.listener.auth;
host =
if
builtins.elem proxyCfg.listener.address [
"0.0.0.0"
"::"
""
]
then
"127.0.0.1"
else
proxyCfg.listener.address;
in
{
inherit auth host;
hostPart = if lib.hasInfix ":" host then "[${host}]" else host;
authEnabled = auth.username != null && (auth.password != null || auth.passwordFile != null);
};
warpCfg = cfg.warp // { warpCfg = cfg.warp // {
# Without a configFile, proxy-suite-warp registers with wgcf into its state dir. # Without a configFile, proxy-suite-warp registers with wgcf into its state dir.
autoRegister = cfg.warp.enable && cfg.warp.configFile == null; autoRegister = cfg.warp.enable && cfg.warp.configFile == null;
@@ -402,13 +424,13 @@ in
{ {
inherit inherit
proxyCfg proxyCfg
localProxy
singBoxCfg singBoxCfg
xrayCfg xrayCfg
proxyEnabled proxyEnabled
singBoxEnabled singBoxEnabled
xrayEnabled xrayEnabled
hybridEnabled hybridEnabled
pureSingBoxEnabled
pureXrayEnabled pureXrayEnabled
activeBackend activeBackend
perAppRoutingCfg perAppRoutingCfg
@@ -426,12 +448,10 @@ in
userControlEnabled userControlEnabled
userControlAllows userControlAllows
sshProxyCfg sshProxyCfg
sshProxyOutboundTag
sshProxyOutboundEnabled sshProxyOutboundEnabled
sshProxyNativeOutbound sshProxyNativeOutbound
sshProxyUnitEnabled sshProxyUnitEnabled
warpCfg warpCfg
warpOutboundTag
warpOutboundEnabled warpOutboundEnabled
torCfg torCfg
torOutboundTag torOutboundTag
@@ -464,7 +484,6 @@ in
outboundTags outboundTags
effectiveOutboundTags effectiveOutboundTags
subscriptionTags subscriptionTags
hasStaticOutbounds
hasSubscriptions hasSubscriptions
hasAvailableOutbounds hasAvailableOutbounds
collapseNamedOutbounds collapseNamedOutbounds
+57
View File
@@ -13,6 +13,63 @@ rec {
); );
forward = forwardWith lib.id; forward = forwardWith lib.id;
# The unit and package forwarding NixOS and system-manager do identically.
systemdForward = internal: {
systemd.services = forward internal.services;
systemd.timers = forward internal.timers;
systemd.paths = forward internal.paths;
systemd.tmpfiles.rules = forward internal.tmpfiles;
environment.systemPackages = lib.mkMerge [
(forwardWith lib.mkBefore internal.earlyPackages)
(forward internal.packages)
];
};
# One system user per daemon, each in a group of its own, plus the userControl group.
systemUsersAndGroups = cfg: {
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
isSystemUser = true;
group = name;
description = "proxy-suite daemons";
});
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
};
firewallPortForward = internal: {
networking.firewall = {
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
};
};
# The rootless adapters (home-manager, nix-on-droid) render the same unit set for a user
# manager: system and user services together, timers and paths, each filtered to enabled.
userUnitsFor =
{
lib,
pkgs,
host,
internal,
hostPath ? null,
}:
let
units = import ./user-units.nix (
{
inherit lib pkgs;
inherit (host) runtimeDir;
stateDir = builtins.dirOf host.stateDir;
}
// lib.optionalAttrs (hostPath != null) { inherit hostPath; }
);
enabled = lib.filterAttrs (_: unit: unit.enable);
in
{
services = lib.mapAttrs units.toService (enabled (internal.services // internal.userServices));
timers = lib.mapAttrs units.toTimer (enabled internal.timers);
paths = lib.mapAttrs units.toPath (enabled internal.paths);
};
# Scripts share one store name per block, and journald names a unit's output # Scripts share one store name per block, and journald names a unit's output
# after its ExecStart basename; tag each unit with its own name instead. # after its ExecStart basename; tag each unit with its own name instead.
unitsWithOwnSyslogIdentifier = lib.mkOption { unitsWithOwnSyslogIdentifier = lib.mkOption {
+11 -17
View File
@@ -13,18 +13,14 @@ let
host = cfg.host; host = cfg.host;
internal = cfg.internal; internal = cfg.internal;
inherit userUnits = (import ./common.nix { inherit lib; }).userUnitsFor {
(import ./user-units.nix { inherit
inherit lib pkgs; lib
inherit (host) runtimeDir; pkgs
stateDir = dirOf host.stateDir; host
}) internal
toService ;
toTimer };
toPath
;
enabled = lib.filterAttrs (_: unit: unit.enable);
in in
{ {
config = lib.mkMerge [ config = lib.mkMerge [
@@ -44,11 +40,9 @@ in
(lib.mkIf cfg.enable ( (lib.mkIf cfg.enable (
lib.mkMerge [ lib.mkMerge [
{ {
systemd.user.services = lib.mapAttrs toService ( systemd.user.services = userUnits.services;
enabled (internal.services // internal.userServices) systemd.user.timers = userUnits.timers;
); systemd.user.paths = userUnits.paths;
systemd.user.timers = lib.mapAttrs toTimer (enabled internal.timers);
systemd.user.paths = lib.mapAttrs toPath (enabled internal.paths);
home.packages = lib.mkMerge [ home.packages = lib.mkMerge [
(lib.mkBefore internal.earlyPackages) (lib.mkBefore internal.earlyPackages)
+10 -19
View File
@@ -15,30 +15,21 @@ let
internal = cfg.internal; internal = cfg.internal;
home = config.user.home; home = config.user.home;
inherit userUnits = (import ./common.nix { inherit lib; }).userUnitsFor {
(import ./user-units.nix { inherit
inherit lib pkgs; lib
inherit (host) runtimeDir; pkgs
stateDir = dirOf host.stateDir; host
hostPath = "${home}/.nix-profile/bin"; internal
}) ;
toService hostPath = "${home}/.nix-profile/bin";
toTimer };
toPath
;
enabled = lib.filterAttrs (_: unit: unit.enable);
supervisorDir = "${host.runtimeDir}/proxy-suite-supervisor"; supervisorDir = "${host.runtimeDir}/proxy-suite-supervisor";
# Outside the store, so proxy-suitectl stays the same from one generation to the next. # Outside the store, so proxy-suitectl stays the same from one generation to the next.
manifestLink = "${host.stateDir}/supervisor/manifest.json"; manifestLink = "${host.stateDir}/supervisor/manifest.json";
manifest = pkgs.writeText "proxy-suite-units.json" ( manifest = pkgs.writeText "proxy-suite-units.json" (
builtins.toJSON { builtins.toJSON (userUnits // { inherit (internal) tmpfiles; })
services = lib.mapAttrs toService (enabled (internal.services // internal.userServices));
timers = lib.mapAttrs toTimer (enabled internal.timers);
paths = lib.mapAttrs toPath (enabled internal.paths);
inherit (internal) tmpfiles;
}
); );
suitectl = import ../../../pkgs/proxy-suite-supervisor.nix { inherit lib pkgs; } { suitectl = import ../../../pkgs/proxy-suite-supervisor.nix { inherit lib pkgs; } {
+22 -30
View File
@@ -12,6 +12,8 @@ let
inherit (import ./common.nix { inherit lib; }) inherit (import ./common.nix { inherit lib; })
forwardWith forwardWith
forward forward
systemdForward
systemUsersAndGroups
unitsWithOwnSyslogIdentifier unitsWithOwnSyslogIdentifier
; ;
in in
@@ -32,39 +34,29 @@ in
}; };
} }
(lib.mkIf cfg.enable { (lib.mkIf cfg.enable (
systemd.services = forward internal.services; lib.mkMerge [
systemd.user.services = forward internal.userServices; (systemdForward internal)
systemd.timers = forward internal.timers; (systemUsersAndGroups cfg)
systemd.paths = forward internal.paths; {
systemd.tmpfiles.rules = forward internal.tmpfiles; systemd.user.services = forward internal.userServices;
environment.systemPackages = lib.mkMerge [ security.polkit.enable = lib.mkIf cfg.internal.polkit.enable true;
(forwardWith lib.mkBefore internal.earlyPackages) security.polkit.extraConfig = forwardWith lib.mkAfter internal.polkit.rules;
(forward internal.packages)
];
users.users = lib.genAttrs cfg.internal.systemUsers (name: { networking.nftables.enable = lib.mkIf cfg.internal.nftables (lib.mkDefault true);
isSystemUser = true; networking.firewall = {
group = name; allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
description = "proxy-suite daemons"; allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
}); extraReversePathFilterRules = forward internal.firewall.extraReversePathFilterRules;
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { }); trustedInterfaces = forward internal.firewall.trustedInterfaces;
};
security.polkit.enable = lib.mkIf cfg.internal.polkit.enable true; boot.extraModulePackages = forward internal.kernelModulePackages;
security.polkit.extraConfig = forwardWith lib.mkAfter internal.polkit.rules; boot.kernel.sysctl = lib.mapAttrs (_: lib.mkDefault) cfg.internal.sysctl;
}
networking.nftables.enable = lib.mkIf cfg.internal.nftables (lib.mkDefault true); ]
networking.firewall = { ))
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
extraReversePathFilterRules = forward internal.firewall.extraReversePathFilterRules;
trustedInterfaces = forward internal.firewall.trustedInterfaces;
};
boot.extraModulePackages = forward internal.kernelModulePackages;
boot.kernel.sysctl = lib.mapAttrs (_: lib.mkDefault) cfg.internal.sysctl;
})
# Off by default since nixpkgs 26.11, and always there before, where the option does # Off by default since nixpkgs 26.11, and always there before, where the option does
# not exist. # not exist.
+29 -41
View File
@@ -14,8 +14,10 @@ let
cfg = config.services.proxy-suite; cfg = config.services.proxy-suite;
internal = options.services.proxy-suite.internal; internal = options.services.proxy-suite.internal;
inherit (import ./common.nix { inherit lib; }) inherit (import ./common.nix { inherit lib; })
forwardWith
forward forward
systemdForward
systemUsersAndGroups
firewallPortForward
unitsWithOwnSyslogIdentifier unitsWithOwnSyslogIdentifier
; ;
@@ -72,47 +74,33 @@ in
}; };
} }
(lib.mkIf cfg.enable { (lib.mkIf cfg.enable (
assertions = [ lib.mkMerge [
(systemdForward internal)
(systemUsersAndGroups cfg)
# Only reported: system-manager leaves the host firewall alone. The routing modes load
# their own nftables tables, and the distribution's loose reverse-path filter already
# lets AmneziaWG replies in.
(firewallPortForward internal)
{ {
assertion = cfg.internal.kernelModulePackages == [ ]; assertions = [
message = "proxy-suite: system-manager cannot load kernel modules from Nix; leave amneziaWg.kernelModulePackage at null"; {
assertion = cfg.internal.kernelModulePackages == [ ];
message = "proxy-suite: system-manager cannot load kernel modules from Nix; leave amneziaWg.kernelModulePackage at null";
}
];
environment.etc = lib.mkMerge [
userServiceFiles
# Read by polkit 0.106 and later; the distribution runs the daemon. The rules
# go through the host's setuid pkexec: nothing here needs a wrapper.
(lib.mkIf cfg.internal.polkit.enable {
"polkit-1/rules.d/50-proxy-suite.rules".text = cfg.internal.polkit.rules;
})
];
} }
]; ]
))
systemd.services = forward internal.services;
systemd.timers = forward internal.timers;
systemd.paths = forward internal.paths;
systemd.tmpfiles.rules = forward internal.tmpfiles;
environment.systemPackages = lib.mkMerge [
(forwardWith lib.mkBefore internal.earlyPackages)
(forward internal.packages)
];
environment.etc = lib.mkMerge [
userServiceFiles
# Read by polkit 0.106 and later; the distribution runs the daemon. The rules
# go through the host's setuid pkexec: nothing here needs a wrapper.
(lib.mkIf cfg.internal.polkit.enable {
"polkit-1/rules.d/50-proxy-suite.rules".text = cfg.internal.polkit.rules;
})
];
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
isSystemUser = true;
group = name;
description = "proxy-suite daemons";
});
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
# Only reported: system-manager leaves the host firewall alone. The routing modes
# load their own nftables tables, and the distribution's loose reverse-path filter
# already lets AmneziaWG replies in.
networking.firewall = {
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
};
})
]; ];
} }
+14
View File
@@ -0,0 +1,14 @@
# The runtime helper scripts (../../../scripts), as one filtered store path shared by every
# module that shells out to them. Unfiltered, the unit tests and any stale __pycache__ land
# in every host's closure and move its store hash.
{ lib }:
builtins.path {
name = "proxy-suite-scripts";
path = ../../../scripts;
filter =
path: _type:
let
base = baseNameOf path;
in
!(lib.hasPrefix "test-" base) && base != "__pycache__";
}
-1
View File
@@ -19,7 +19,6 @@
./tg-ws-proxy.nix ./tg-ws-proxy.nix
./geodata.nix ./geodata.nix
./gui.nix ./gui.nix
./tray.nix
./tui.nix ./tui.nix
./user-control.nix ./user-control.nix
./host.nix ./host.nix
+1 -6
View File
@@ -9,12 +9,7 @@ let
types types
; ;
t = import ./types.nix { inherit lib; }; t = import ./types.nix { inherit lib; };
bool = inherit (import ./lib.nix { inherit lib; }) bool;
default: description:
mkOption {
type = types.bool;
inherit default description;
};
in in
{ {
options.services.proxy-suite.inbounds = { options.services.proxy-suite.inbounds = {
+47
View File
@@ -0,0 +1,47 @@
# The option shapes this module declares over and over, in one place.
{ lib }:
let
inherit (lib) mkOption types;
in
{
list =
description: example:
mkOption {
type = types.listOf types.str;
default = [ ];
inherit description example;
};
nullStr =
description: example:
mkOption {
type = types.nullOr types.str;
default = null;
inherit description example;
};
bool =
default: description:
mkOption {
type = types.bool;
inherit default description;
};
int =
default: description:
mkOption {
type = types.int;
inherit default description;
};
positiveInt =
default: description:
mkOption {
type = types.ints.positive;
inherit default description;
};
# An option path under services.proxy-suite, for the compatibility modules.
path =
path:
[
"services"
"proxy-suite"
]
++ lib.splitString "." path;
}
@@ -3,12 +3,7 @@
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
t = import ./types.nix { inherit lib; }; t = import ./types.nix { inherit lib; };
int = inherit (import ./lib.nix { inherit lib; }) int;
default: description:
mkOption {
type = types.int;
inherit default description;
};
localSubnets = localSubnets =
description: description:
mkOption { mkOption {
@@ -3,13 +3,7 @@
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
t = import ./types.nix { inherit lib; }; t = import ./types.nix { inherit lib; };
list = inherit (import ./lib.nix { inherit lib; }) list;
description: example:
mkOption {
type = types.listOf types.str;
default = [ ];
inherit description example;
};
in in
{ {
options.services.proxy-suite.proxy.routing = { options.services.proxy-suite.proxy.routing = {
+6 -7
View File
@@ -1,13 +1,7 @@
{ lib, ... }: { lib, ... }:
let let
p = p = (import ./lib.nix { inherit lib; }).path;
path:
[
"services"
"proxy-suite"
]
++ lib.splitString "." path;
rm = path: replacement: lib.mkRemovedOptionModule (p path) replacement; rm = path: replacement: lib.mkRemovedOptionModule (p path) replacement;
# Top-level zapret options that moved under the engine namespace; the value is # Top-level zapret options that moved under the engine namespace; the value is
# the leaf name they carry there. # the leaf name they carry there.
@@ -24,6 +18,11 @@ let
in in
{ {
imports = [ imports = [
# The tray indicator became Proxy Suite GUI, which has the tray icon built in.
(lib.mkRenamedOptionModule (p "tray.enable") (p "gui.enable"))
(lib.mkRenamedOptionModule (p "tray.autostart") (p "gui.autostart"))
(lib.mkRenamedOptionModule (p "tray.pollInterval") (p "gui.refreshInterval"))
# These were aliases; they are removal notices now, so there is one # These were aliases; they are removal notices now, so there is one
# compatibility policy instead of two. # compatibility policy instead of two.
(rm "proxyInbounds" "Use services.proxy-suite.inbounds.") (rm "proxyInbounds" "Use services.proxy-suite.inbounds.")
+1 -7
View File
@@ -3,13 +3,7 @@
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
token = types.nullOr (types.strMatching "[^[:space:]]+"); token = types.nullOr (types.strMatching "[^[:space:]]+");
path = path = (import ./lib.nix { inherit lib; }).nullStr;
description: example:
mkOption {
type = types.nullOr types.str;
default = null;
inherit description example;
};
in in
{ {
options.services.proxy-suite.sshProxy = { options.services.proxy-suite.sshProxy = {
+1 -7
View File
@@ -2,13 +2,7 @@
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
domains = domains = (import ./lib.nix { inherit lib; }).list;
description: example:
mkOption {
type = types.listOf types.str;
default = [ ];
inherit description example;
};
in in
{ {
options.services.proxy-suite.tgWsProxy = { options.services.proxy-suite.tgWsProxy = {
-19
View File
@@ -1,19 +0,0 @@
{ lib, ... }:
let
p =
path:
[
"services"
"proxy-suite"
]
++ lib.splitString "." path;
in
{
# The tray indicator became Proxy Suite GUI, which has the tray icon built in.
imports = [
(lib.mkRenamedOptionModule (p "tray.enable") (p "gui.enable"))
(lib.mkRenamedOptionModule (p "tray.autostart") (p "gui.autostart"))
(lib.mkRenamedOptionModule (p "tray.pollInterval") (p "gui.refreshInterval"))
];
}
+1 -8
View File
@@ -2,14 +2,7 @@
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
inherit (import ./lib.nix { inherit lib; }) list;
list =
description: example:
mkOption {
type = types.listOf types.str;
default = [ ];
inherit description example;
};
routingFields = { routingFields = {
domains = list "Domain suffixes to match." [ "youtube.com" ]; domains = list "Domain suffixes to match." [ "youtube.com" ];
+43 -132
View File
@@ -54,139 +54,50 @@ let
}; };
}; };
obfuscationType = types.submodule { # Every AWG obfuscation field is an optional scalar with a one-line description, so they
options = { # are declared as tables per value type rather than 27 near-identical mkOption blocks.
jc = mkOption { optional =
type = optionalUnsigned; type: description:
default = null; mkOption {
description = "Junk packet count (Jc)."; inherit type description;
}; default = null;
jmin = mkOption {
type = optionalUnsigned;
default = null;
description = "Minimum junk packet size (Jmin).";
};
jmax = mkOption {
type = optionalUnsigned;
default = null;
description = "Maximum junk packet size (Jmax).";
};
s1 = mkOption {
type = optionalUnsigned;
default = null;
description = "Handshake-init padding (S1).";
};
s2 = mkOption {
type = optionalUnsigned;
default = null;
description = "Handshake-response padding (S2).";
};
s3 = mkOption {
type = optionalUnsigned;
default = null;
description = "Cookie-reply padding (S3).";
};
s4 = mkOption {
type = optionalUnsigned;
default = null;
description = "Transport-message padding (S4).";
};
h1 = mkOption {
type = optionalRange;
default = null;
description = "Handshake-init header or range (H1).";
};
h2 = mkOption {
type = optionalRange;
default = null;
description = "Handshake-response header or range (H2).";
};
h3 = mkOption {
type = optionalRange;
default = null;
description = "Cookie-reply header or range (H3).";
};
h4 = mkOption {
type = optionalRange;
default = null;
description = "Transport-message header or range (H4).";
};
i1 = mkOption {
type = optionalString;
default = null;
description = "First custom signature packet (I1).";
};
i2 = mkOption {
type = optionalString;
default = null;
description = "Second custom signature packet (I2).";
};
i3 = mkOption {
type = optionalString;
default = null;
description = "Third custom signature packet (I3).";
};
i4 = mkOption {
type = optionalString;
default = null;
description = "Fourth custom signature packet (I4).";
};
i5 = mkOption {
type = optionalString;
default = null;
description = "Fifth custom signature packet (I5).";
};
headerProtectionKey = mkOption {
type = optionalString;
default = null;
description = "Inline AWG 3 header-protection key. Prefer headerProtectionKeyFile.";
};
headerProtectionKeyFile = mkOption {
type = optionalString;
default = null;
description = "Runtime path containing the AWG 3 header-protection key.";
};
contentPaddingAddition = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 content-padding addition or range.";
};
rekeyAfterTime = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 rekey interval or range.";
};
rekeyTimeout = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 rekey timeout or range.";
};
rejectAfterTime = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 reject-after interval or range.";
};
keepaliveTimeout = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 keepalive timeout or range.";
};
maxHandshakeAttempts = mkOption {
type = optionalRange;
default = null;
description = "AWG 3 maximum handshake attempts or range.";
};
randomTrailers = mkOption {
type = types.nullOr types.bool;
default = null;
description = "AWG 3 random transport trailers (RandomTrailers).";
};
disableCookies = mkOption {
type = types.nullOr types.bool;
default = null;
description = "AWG 3 cookie suppression (DisableCookies).";
};
}; };
obfuscationType = types.submodule {
options =
lib.mapAttrs (_: optional optionalUnsigned) {
jc = "Junk packet count (Jc).";
jmin = "Minimum junk packet size (Jmin).";
jmax = "Maximum junk packet size (Jmax).";
s1 = "Handshake-init padding (S1).";
s2 = "Handshake-response padding (S2).";
s3 = "Cookie-reply padding (S3).";
s4 = "Transport-message padding (S4).";
}
// lib.mapAttrs (_: optional optionalRange) {
h1 = "Handshake-init header or range (H1).";
h2 = "Handshake-response header or range (H2).";
h3 = "Cookie-reply header or range (H3).";
h4 = "Transport-message header or range (H4).";
contentPaddingAddition = "AWG 3 content-padding addition or range.";
rekeyAfterTime = "AWG 3 rekey interval or range.";
rekeyTimeout = "AWG 3 rekey timeout or range.";
rejectAfterTime = "AWG 3 reject-after interval or range.";
keepaliveTimeout = "AWG 3 keepalive timeout or range.";
maxHandshakeAttempts = "AWG 3 maximum handshake attempts or range.";
}
// lib.mapAttrs (_: optional optionalString) {
i1 = "First custom signature packet (I1).";
i2 = "Second custom signature packet (I2).";
i3 = "Third custom signature packet (I3).";
i4 = "Fourth custom signature packet (I4).";
i5 = "Fifth custom signature packet (I5).";
headerProtectionKey = "Inline AWG 3 header-protection key. Prefer headerProtectionKeyFile.";
headerProtectionKeyFile = "Runtime path containing the AWG 3 header-protection key.";
}
// lib.mapAttrs (_: optional (types.nullOr types.bool)) {
randomTrailers = "AWG 3 random transport trailers (RandomTrailers).";
disableCookies = "AWG 3 cookie suppression (DisableCookies).";
};
}; };
settingsType = types.submodule { settingsType = types.submodule {
@@ -3,13 +3,7 @@
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
inherit (import ./amnezia-wg.nix { inherit lib; }) obfuscationType; inherit (import ./amnezia-wg.nix { inherit lib; }) obfuscationType;
nullStr = inherit (import ../lib.nix { inherit lib; }) nullStr;
description: example:
mkOption {
type = types.nullOr types.str;
default = null;
inherit description example;
};
userType = types.submodule { userType = types.submodule {
options = { options = {
@@ -2,13 +2,7 @@
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
nullStr = inherit (import ../lib.nix { inherit lib; }) nullStr;
description: example:
mkOption {
type = types.nullOr types.str;
default = null;
inherit description example;
};
nullAttrs = nullAttrs =
description: example: description: example:
mkOption { mkOption {
+1 -13
View File
@@ -3,19 +3,7 @@
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
t = import ./types.nix { inherit lib; }; t = import ./types.nix { inherit lib; };
list = inherit (import ./lib.nix { inherit lib; }) list bool;
description: example:
mkOption {
type = types.listOf types.str;
default = [ ];
inherit description example;
};
bool =
default: description:
mkOption {
type = types.bool;
inherit default description;
};
in in
{ {
options.services.proxy-suite.zapret = { options.services.proxy-suite.zapret = {
+1 -6
View File
@@ -2,12 +2,7 @@
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
int = int = (import ./lib.nix { inherit lib; }).positiveInt;
default: description:
mkOption {
type = types.ints.positive;
inherit default description;
};
fromSource = what: "null uses the ${what} of strategySource."; fromSource = what: "null uses the ${what} of strategySource.";
in in
{ {
+160 -279
View File
@@ -38,9 +38,10 @@ let
requireEnabled = requireEnabled =
featureEnabled: dependencyEnabled: message: featureEnabled: dependencyEnabled: message:
mkAssertion (!featureEnabled || dependencyEnabled) message; mkAssertion (!featureEnabled || dependencyEnabled) message;
requireAvailable = # The shape of nearly every dependency assertion: "<used> requires <dependency> = true".
featureUsed: dependencyEnabled: message: requires =
mkAssertion (!featureUsed || dependencyEnabled) message; used: dependency: usedLabel: dependencyLabel:
mkAssertion (!used || dependency) "proxy-suite: ${usedLabel} requires ${dependencyLabel} = true";
uniqueValues = uniqueValues =
condition: values: message: condition: values: message:
mkAssertion (!condition || builtins.length values == builtins.length (lib.unique values)) message; mkAssertion (!condition || builtins.length values == builtins.length (lib.unique values)) message;
@@ -55,6 +56,13 @@ let
forbiddenValues = forbiddenValues =
condition: value: disallowed: message: condition: value: disallowed: message:
mkAssertion (!(condition && builtins.elem value disallowed)) message; mkAssertion (!(condition && builtins.elem value disallowed)) message;
# Two values that must not coincide; the message names the config that conflicts them.
distinct =
condition: left: right: message:
notEqualWhen condition left right "proxy-suite: ${message}";
positive =
condition: value: label:
mkAssertion (!condition || value > 0) "proxy-suite: ${label} must be greater than zero";
# Every loopback listener proxy-suite opens with a fixed port of its own, which # Every loopback listener proxy-suite opens with a fixed port of its own, which
# the autoProxy prober's range must stay clear of. # the autoProxy prober's range must stay clear of.
@@ -238,54 +246,49 @@ let
) )
]; ];
# Each case reads "<used> requires <dependency> = true", with option paths as labels.
perAppRoutingAssertions = [ perAppRoutingAssertions = [
(requireAvailable (perAppRoutingCfg.profiles != [ ]) perAppRoutingCfg.enable (requires (
"proxy-suite: perAppRouting.profiles requires perAppRouting.enable = true" perAppRoutingCfg.profiles != [ ]
) perAppRoutingCfg.enable "perAppRouting.profiles" "perAppRouting.enable")
(requires perAppRoutingCfg.proxychains.enable perAppRoutingCfg.enable
"perAppRouting.proxychains.enable"
"perAppRouting.enable"
) )
(requireEnabled perAppRoutingCfg.proxychains.enable perAppRoutingCfg.enable (requires perAppRoutingCfg.proxychains.enable proxyEnabled "perAppRouting.proxychains.enable"
"proxy-suite: perAppRouting.proxychains.enable requires perAppRouting.enable = true" "proxy.enable"
)
(requireEnabled perAppRoutingCfg.proxychains.enable proxyEnabled
"proxy-suite: perAppRouting.proxychains.enable requires proxy.enable = true"
) )
(uniqueValues true effectivePerAppRoutingProfileNames (uniqueValues true effectivePerAppRoutingProfileNames
"proxy-suite: perAppRouting profile names must be unique" "proxy-suite: perAppRouting profile names must be unique"
) )
(requireAvailable hasProxychainsProfiles perAppRoutingCfg.proxychains.enable (requires hasProxychainsProfiles perAppRoutingCfg.proxychains.enable
"proxy-suite: route=proxychains in perAppRouting.profiles requires perAppRouting.proxychains.enable = true" "route=proxychains in perAppRouting.profiles"
"perAppRouting.proxychains.enable"
) )
(requireAvailable hasProxychainsProfiles proxyEnabled (requires hasProxychainsProfiles proxyEnabled "route=proxychains in perAppRouting.profiles"
"proxy-suite: route=proxychains in perAppRouting.profiles requires proxy.enable = true" "proxy.enable"
) )
(requireEnabled perAppRoutingTun.enable perAppRoutingCfg.enable (requires perAppRoutingTun.enable perAppRoutingCfg.enable "perAppRouting.tun.enable"
"proxy-suite: perAppRouting.tun.enable requires perAppRouting.enable = true" "perAppRouting.enable"
) )
(requireEnabled perAppRoutingTun.enable proxyEnabled (requires perAppRoutingTun.enable proxyEnabled "perAppRouting.tun.enable" "proxy.enable")
"proxy-suite: perAppRouting.tun.enable requires proxy.enable = true" (requires hasTunProfiles perAppRoutingTun.enable "route=tun in perAppRouting.profiles"
"perAppRouting.tun.enable"
) )
(requireAvailable hasTunProfiles perAppRoutingTun.enable (requires hasTunProfiles proxyEnabled "route=tun in perAppRouting.profiles" "proxy.enable")
"proxy-suite: route=tun in perAppRouting.profiles requires perAppRouting.tun.enable = true" (requires perAppRoutingTproxy.enable perAppRoutingCfg.enable "perAppRouting.tproxy.enable"
"perAppRouting.enable"
) )
(requireAvailable hasTunProfiles proxyEnabled (requires perAppRoutingTproxy.enable proxyEnabled "perAppRouting.tproxy.enable" "proxy.enable")
"proxy-suite: route=tun in perAppRouting.profiles requires proxy.enable = true" (requires hasTproxyProfiles perAppRoutingTproxy.enable "route=tproxy in perAppRouting.profiles"
"perAppRouting.tproxy.enable"
) )
(requireEnabled perAppRoutingTproxy.enable perAppRoutingCfg.enable (requires hasTproxyProfiles proxyEnabled "route=tproxy in perAppRouting.profiles" "proxy.enable")
"proxy-suite: perAppRouting.tproxy.enable requires perAppRouting.enable = true" (requires perAppZapretCfg.enable perAppRoutingCfg.enable "perAppRouting.zapret.enable"
"perAppRouting.enable"
) )
(requireEnabled perAppRoutingTproxy.enable proxyEnabled (requires hasZapretProfiles perAppZapretCfg.enable "route=zapret in perAppRouting.profiles"
"proxy-suite: perAppRouting.tproxy.enable requires proxy.enable = true" "perAppRouting.zapret.enable"
)
(requireAvailable hasTproxyProfiles perAppRoutingTproxy.enable
"proxy-suite: route=tproxy in perAppRouting.profiles requires perAppRouting.tproxy.enable = true"
)
(requireAvailable hasTproxyProfiles proxyEnabled
"proxy-suite: route=tproxy in perAppRouting.profiles requires proxy.enable = true"
)
(requireEnabled perAppZapretCfg.enable perAppRoutingCfg.enable
"proxy-suite: perAppRouting.zapret.enable requires perAppRouting.enable = true"
)
(requireAvailable hasZapretProfiles perAppZapretCfg.enable
"proxy-suite: route=zapret in perAppRouting.profiles requires perAppRouting.zapret.enable = true"
) )
]; ];
@@ -528,7 +531,7 @@ let
(mkAssertion ( (mkAssertion (
!proxyInboundsEnabled || !l.reality.enable || l.reality.serverNames != [ ] !proxyInboundsEnabled || !l.reality.enable || l.reality.serverNames != [ ]
) "${prefix}: reality.serverNames must not be empty") ) "${prefix}: reality.serverNames must not be empty")
(requireAvailable (proxyInboundsEnabled && l.reality.enable && proxyInboundsCfg.shareLinks) (requireEnabled (proxyInboundsEnabled && l.reality.enable && proxyInboundsCfg.shareLinks)
(l.reality.publicKey != null) (l.reality.publicKey != null)
"${prefix}: reality.publicKey is required to generate share links. Run `xray x25519` to print it alongside the private key, or set inbounds.shareLinks = false." "${prefix}: reality.publicKey is required to generate share links. Run `xray x25519` to print it alongside the private key, or set inbounds.shareLinks = false."
) )
@@ -692,254 +695,132 @@ let
globalTunAutoRouteTable = constants.tunAutoRouteTableIndex; globalTunAutoRouteTable = constants.tunAutoRouteTableIndex;
globalZapretQnum = constants.zapretGlobalQnum.${zapretEngine}; globalZapretQnum = constants.zapretGlobalQnum.${zapretEngine};
collisionAssertions = map (item: notEqualWhen item.condition item.left item.right item.message) [ collisionAssertions =
{ let
condition = globalTun.enable && perAppRoutingTun.enable; bothTun = globalTun.enable && perAppRoutingTun.enable;
left = globalTun.interface; perAppTunWithTproxy = perAppRoutingTun.enable && globalTproxy.enable;
right = perAppRoutingTun.interface; bothPerApp = perAppRoutingTun.enable && perAppRoutingTproxy.enable;
message = "proxy-suite: proxy.tun.interface and perAppRouting.tun.interface must differ"; tgWsBypass = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
} in
{ [
condition = globalTun.enable && perAppRoutingTun.enable; (distinct bothTun globalTun.interface perAppRoutingTun.interface
left = globalTun.address; "proxy.tun.interface and perAppRouting.tun.interface must differ"
right = perAppRoutingTun.address; )
message = "proxy-suite: proxy.tun.address and perAppRouting.tun.address must differ"; (distinct bothTun globalTun.address perAppRoutingTun.address
} "proxy.tun.address and perAppRouting.tun.address must differ"
{ )
condition = globalTun.enable && perAppRoutingTun.enable; (distinct bothTun perAppRoutingTun.routeTable globalTunAutoRouteTable
left = perAppRoutingTun.routeTable; "perAppRouting.tun.routeTable must differ from the global TUN auto-route table ${toString globalTunAutoRouteTable}"
right = globalTunAutoRouteTable; )
message = "proxy-suite: perAppRouting.tun.routeTable must differ from the global TUN auto-route table ${toString globalTunAutoRouteTable}"; (distinct perAppTunWithTproxy perAppRoutingTun.fwmark globalTproxy.fwmark
} "perAppRouting.tun.fwmark must differ from proxy.tproxy.fwmark when global TProxy is enabled"
{ )
condition = perAppRoutingTun.enable && globalTproxy.enable; (distinct perAppTunWithTproxy perAppRoutingTun.fwmark globalTproxy.proxyMark
left = perAppRoutingTun.fwmark; "perAppRouting.tun.fwmark must differ from proxy.tproxy.proxyMark when global TProxy is enabled"
right = globalTproxy.fwmark; )
message = "proxy-suite: perAppRouting.tun.fwmark must differ from proxy.tproxy.fwmark when global TProxy is enabled"; (distinct perAppTunWithTproxy perAppRoutingTun.routeTable globalTproxy.routeTable
} "perAppRouting.tun.routeTable must differ from proxy.tproxy.routeTable when global TProxy is enabled"
{ )
condition = perAppRoutingTun.enable && globalTproxy.enable; (distinct (perAppZapretCfg.enable && zapretCfg.enable) perAppZapretCfg.qnum globalZapretQnum
left = perAppRoutingTun.fwmark; "perAppRouting.zapret.qnum must differ from the global zapret instance's NFQUEUE ${toString globalZapretQnum}"
right = globalTproxy.proxyMark; )
message = "proxy-suite: perAppRouting.tun.fwmark must differ from proxy.tproxy.proxyMark when global TProxy is enabled"; (distinct perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark globalTproxy.fwmark
} "perAppRouting.tproxy.fwmark must differ from proxy.tproxy.fwmark"
{ )
condition = perAppRoutingTun.enable && globalTproxy.enable; (distinct perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark globalTproxy.proxyMark
left = perAppRoutingTun.routeTable; "perAppRouting.tproxy.fwmark must differ from proxy.tproxy.proxyMark"
right = globalTproxy.routeTable; )
message = "proxy-suite: perAppRouting.tun.routeTable must differ from proxy.tproxy.routeTable when global TProxy is enabled"; (distinct perAppRoutingTproxy.enable perAppRoutingTproxy.routeTable globalTproxy.routeTable
} "perAppRouting.tproxy.routeTable must differ from proxy.tproxy.routeTable"
{ )
condition = perAppZapretCfg.enable && zapretCfg.enable; (distinct bothPerApp perAppRoutingTun.fwmark perAppRoutingTproxy.fwmark
left = perAppZapretCfg.qnum; "perAppRouting.tun.fwmark and perAppRouting.tproxy.fwmark must differ"
right = globalZapretQnum; )
message = "proxy-suite: perAppRouting.zapret.qnum must differ from the global zapret instance's NFQUEUE ${toString globalZapretQnum}"; (distinct bothPerApp perAppRoutingTun.routeTable perAppRoutingTproxy.routeTable
} "perAppRouting.tun.routeTable and perAppRouting.tproxy.routeTable must differ"
{ )
condition = perAppRoutingTproxy.enable; (distinct perAppZapretCfg.enable perAppZapretCfg.filterMark globalTproxy.fwmark
left = perAppRoutingTproxy.fwmark; "perAppRouting.zapret.filterMark must differ from proxy.tproxy.fwmark"
right = globalTproxy.fwmark; )
message = "proxy-suite: perAppRouting.tproxy.fwmark must differ from proxy.tproxy.fwmark"; (distinct perAppZapretCfg.enable perAppZapretCfg.filterMark globalTproxy.proxyMark
} "perAppRouting.zapret.filterMark must differ from proxy.tproxy.proxyMark"
{ )
condition = perAppRoutingTproxy.enable; (distinct (perAppRoutingTun.enable && perAppZapretCfg.enable) perAppRoutingTun.fwmark
left = perAppRoutingTproxy.fwmark; perAppZapretCfg.filterMark
right = globalTproxy.proxyMark; "perAppRouting.tun.fwmark and perAppRouting.zapret.filterMark must differ"
message = "proxy-suite: perAppRouting.tproxy.fwmark must differ from proxy.tproxy.proxyMark"; )
} (distinct (perAppRoutingTproxy.enable && perAppZapretCfg.enable) perAppRoutingTproxy.fwmark
{ perAppZapretCfg.filterMark
condition = perAppRoutingTproxy.enable; "perAppRouting.tproxy.fwmark and perAppRouting.zapret.filterMark must differ"
left = perAppRoutingTproxy.routeTable; )
right = globalTproxy.routeTable; (distinct (
message = "proxy-suite: perAppRouting.tproxy.routeTable must differ from proxy.tproxy.routeTable"; tgWsBypass && globalTproxy.enable
} ) tgWsProxyCfg.fwmark globalTproxy.fwmark "tgWsProxy.fwmark must differ from proxy.tproxy.fwmark")
{ (distinct (tgWsBypass && globalTproxy.enable) tgWsProxyCfg.fwmark globalTproxy.proxyMark
condition = perAppRoutingTun.enable && perAppRoutingTproxy.enable; "tgWsProxy.fwmark must differ from proxy.tproxy.proxyMark"
left = perAppRoutingTun.fwmark; )
right = perAppRoutingTproxy.fwmark; (distinct (tgWsBypass && perAppRoutingTun.enable) tgWsProxyCfg.fwmark perAppRoutingTun.fwmark
message = "proxy-suite: perAppRouting.tun.fwmark and perAppRouting.tproxy.fwmark must differ"; "tgWsProxy.fwmark must differ from perAppRouting.tun.fwmark"
} )
{ (distinct (tgWsBypass && perAppRoutingTproxy.enable) tgWsProxyCfg.fwmark perAppRoutingTproxy.fwmark
condition = perAppRoutingTun.enable && perAppRoutingTproxy.enable; "tgWsProxy.fwmark must differ from perAppRouting.tproxy.fwmark"
left = perAppRoutingTun.routeTable; )
right = perAppRoutingTproxy.routeTable; (distinct (tgWsBypass && perAppZapretCfg.enable) tgWsProxyCfg.fwmark perAppZapretCfg.filterMark
message = "proxy-suite: perAppRouting.tun.routeTable and perAppRouting.tproxy.routeTable must differ"; "tgWsProxy.fwmark must differ from perAppRouting.zapret.filterMark"
} )
{ ];
condition = perAppZapretCfg.enable;
left = perAppZapretCfg.filterMark;
right = globalTproxy.fwmark;
message = "proxy-suite: perAppRouting.zapret.filterMark must differ from proxy.tproxy.fwmark";
}
{
condition = perAppZapretCfg.enable;
left = perAppZapretCfg.filterMark;
right = globalTproxy.proxyMark;
message = "proxy-suite: perAppRouting.zapret.filterMark must differ from proxy.tproxy.proxyMark";
}
{
condition = perAppRoutingTun.enable && perAppZapretCfg.enable;
left = perAppRoutingTun.fwmark;
right = perAppZapretCfg.filterMark;
message = "proxy-suite: perAppRouting.tun.fwmark and perAppRouting.zapret.filterMark must differ";
}
{
condition = perAppRoutingTproxy.enable && perAppZapretCfg.enable;
left = perAppRoutingTproxy.fwmark;
right = perAppZapretCfg.filterMark;
message = "proxy-suite: perAppRouting.tproxy.fwmark and perAppRouting.zapret.filterMark must differ";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && globalTproxy.enable;
left = tgWsProxyCfg.fwmark;
right = globalTproxy.fwmark;
message = "proxy-suite: tgWsProxy.fwmark must differ from proxy.tproxy.fwmark";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && globalTproxy.enable;
left = tgWsProxyCfg.fwmark;
right = globalTproxy.proxyMark;
message = "proxy-suite: tgWsProxy.fwmark must differ from proxy.tproxy.proxyMark";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTun.enable;
left = tgWsProxyCfg.fwmark;
right = perAppRoutingTun.fwmark;
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.tun.fwmark";
}
{
condition =
tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTproxy.enable;
left = tgWsProxyCfg.fwmark;
right = perAppRoutingTproxy.fwmark;
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.tproxy.fwmark";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppZapretCfg.enable;
left = tgWsProxyCfg.fwmark;
right = perAppZapretCfg.filterMark;
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.zapret.filterMark";
}
];
perAppZapretDesyncMarks = [ perAppZapretDesyncMarks = [
67108864 67108864
134217728 134217728
]; ];
positiveNumberAssertions = positiveNumberAssertions = [
map (item: mkAssertion (!item.condition || item.value > 0) item.message) (positive globalTun.enable globalTun.mtu "proxy.tun.mtu")
[ (positive perAppRoutingTun.enable perAppRoutingTun.mtu "perAppRouting.tun.mtu")
{ (positive globalTproxy.enable globalTproxy.fwmark "proxy.tproxy.fwmark")
condition = globalTun.enable; (positive globalTproxy.enable globalTproxy.proxyMark "proxy.tproxy.proxyMark")
value = globalTun.mtu; (positive globalTproxy.enable globalTproxy.routeTable "proxy.tproxy.routeTable")
message = "proxy-suite: proxy.tun.mtu must be greater than zero"; (positive perAppRoutingTun.enable perAppRoutingTun.fwmark "perAppRouting.tun.fwmark")
} (positive perAppRoutingTun.enable perAppRoutingTun.routeTable "perAppRouting.tun.routeTable")
{ (positive perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark "perAppRouting.tproxy.fwmark")
condition = perAppRoutingTun.enable; (positive perAppRoutingTproxy.enable perAppRoutingTproxy.routeTable
value = perAppRoutingTun.mtu; "perAppRouting.tproxy.routeTable"
message = "proxy-suite: perAppRouting.tun.mtu must be greater than zero"; )
} (positive perAppZapretCfg.enable perAppZapretCfg.filterMark "perAppRouting.zapret.filterMark")
{ (positive perAppZapretCfg.enable perAppZapretCfg.qnum "perAppRouting.zapret.qnum")
condition = globalTproxy.enable; (positive (
value = globalTproxy.fwmark; tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy
message = "proxy-suite: proxy.tproxy.fwmark must be greater than zero"; ) tgWsProxyCfg.fwmark "tgWsProxy.fwmark")
} ];
{
condition = globalTproxy.enable;
value = globalTproxy.proxyMark;
message = "proxy-suite: proxy.tproxy.proxyMark must be greater than zero";
}
{
condition = globalTproxy.enable;
value = globalTproxy.routeTable;
message = "proxy-suite: proxy.tproxy.routeTable must be greater than zero";
}
{
condition = perAppRoutingTun.enable;
value = perAppRoutingTun.fwmark;
message = "proxy-suite: perAppRouting.tun.fwmark must be greater than zero";
}
{
condition = perAppRoutingTun.enable;
value = perAppRoutingTun.routeTable;
message = "proxy-suite: perAppRouting.tun.routeTable must be greater than zero";
}
{
condition = perAppRoutingTproxy.enable;
value = perAppRoutingTproxy.fwmark;
message = "proxy-suite: perAppRouting.tproxy.fwmark must be greater than zero";
}
{
condition = perAppRoutingTproxy.enable;
value = perAppRoutingTproxy.routeTable;
message = "proxy-suite: perAppRouting.tproxy.routeTable must be greater than zero";
}
{
condition = perAppZapretCfg.enable;
value = perAppZapretCfg.filterMark;
message = "proxy-suite: perAppRouting.zapret.filterMark must be greater than zero";
}
{
condition = perAppZapretCfg.enable;
value = perAppZapretCfg.qnum;
message = "proxy-suite: perAppRouting.zapret.qnum must be greater than zero";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
value = tgWsProxyCfg.fwmark;
message = "proxy-suite: tgWsProxy.fwmark must be greater than zero";
}
];
forbiddenValueAssertions = forbiddenValueAssertions =
map (item: forbiddenValues item.condition item.value item.disallowed item.message) let
[ # zapret's own desync marks: v1's pair, and the bits nfqws2 sets for per-app zapret.
{ zapretInternalMarks = [
condition = perAppZapretCfg.enable; 536870912
value = perAppZapretCfg.filterMark; 1073741824
disallowed = [
536870912
1073741824
];
message = "proxy-suite: perAppRouting.zapret.filterMark must not use zapret internal desync mark bits";
}
{
condition = perAppZapretCfg.enable;
value = globalTproxy.fwmark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: proxy.tproxy.fwmark must not use per-app-zapret internal desync mark bits";
}
{
condition = perAppZapretCfg.enable;
value = globalTproxy.proxyMark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: proxy.tproxy.proxyMark must not use per-app-zapret internal desync mark bits";
}
{
condition = perAppRoutingTun.enable && perAppZapretCfg.enable;
value = perAppRoutingTun.fwmark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: perAppRouting.tun.fwmark must not use per-app-zapret internal desync mark bits";
}
{
condition = perAppRoutingTproxy.enable && perAppZapretCfg.enable;
value = perAppRoutingTproxy.fwmark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: perAppRouting.tproxy.fwmark must not use per-app-zapret internal desync mark bits";
}
{
condition = perAppZapretCfg.enable;
value = perAppZapretCfg.filterMark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: perAppRouting.zapret.filterMark must not use per-app-zapret internal desync mark bits";
}
{
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppZapretCfg.enable;
value = tgWsProxyCfg.fwmark;
disallowed = perAppZapretDesyncMarks;
message = "proxy-suite: tgWsProxy.fwmark must not use per-app-zapret internal desync mark bits";
}
]; ];
noDesyncBits =
condition: value: label:
forbiddenValues condition value perAppZapretDesyncMarks
"proxy-suite: ${label} must not use per-app-zapret internal desync mark bits";
tgWsBypass = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
in
[
(forbiddenValues perAppZapretCfg.enable perAppZapretCfg.filterMark zapretInternalMarks
"proxy-suite: perAppRouting.zapret.filterMark must not use zapret internal desync mark bits"
)
(noDesyncBits perAppZapretCfg.enable globalTproxy.fwmark "proxy.tproxy.fwmark")
(noDesyncBits perAppZapretCfg.enable globalTproxy.proxyMark "proxy.tproxy.proxyMark")
(noDesyncBits (
perAppRoutingTun.enable && perAppZapretCfg.enable
) perAppRoutingTun.fwmark "perAppRouting.tun.fwmark")
(noDesyncBits (
perAppRoutingTproxy.enable && perAppZapretCfg.enable
) perAppRoutingTproxy.fwmark "perAppRouting.tproxy.fwmark")
(noDesyncBits perAppZapretCfg.enable perAppZapretCfg.filterMark "perAppRouting.zapret.filterMark")
(noDesyncBits (tgWsBypass && perAppZapretCfg.enable) tgWsProxyCfg.fwmark "tgWsProxy.fwmark")
];
torCfg = cfg.tor; torCfg = cfg.tor;
torOnionListeners = torOnionListeners =
+35 -149
View File
@@ -13,54 +13,15 @@
perAppTunChainFile, perAppTunChainFile,
perAppTproxyRulesFile, perAppTproxyRulesFile,
perAppZapretRulesFile, perAppZapretRulesFile,
nftablesRulesFile,
ip, ip,
nft, nft,
}: }:
let let
derived = import ../derived.nix { inherit lib cfg; }; derived = import ../derived.nix { inherit lib cfg; };
constants = derived.constants; # Only what this file itself needs; the rest reaches the sub-modules through ctx.
inherit (derived) inherit (derived) singBoxCfg xrayCfg userControlCfg;
singBoxCfg
proxyCfg
xrayCfg
proxyEnabled
singBoxEnabled
xrayEnabled
hybridEnabled
pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
globalTproxy
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
zapretEngine
zapretCutoffEnabled
zapretCutoffProxyFallback
userControlCfg
selectionMode
builtinTags
outboundTags
subscriptionTags
invalidRoutingTargets
collapseNamedOutbounds
sshProxyCfg
sshProxyOutboundEnabled
sshProxyUnitEnabled
warpCfg
torCfg
awgOutbounds
proxyInboundsCfg
proxyInboundsEnabled
proxyInboundsAwg
proxyInboundsNeedLocalProxy
torOnionEnabled
proxyInboundsGuardPrivate
proxyInboundViaOutbounds
userControlAllows
;
# Tool paths – defined once here and passed into sub-modules as needed. # Tool paths – defined once here and passed into sub-modules as needed.
jq = "${pkgs.jq}/bin/jq"; jq = "${pkgs.jq}/bin/jq";
@@ -81,10 +42,7 @@ let
) )
); );
proxySuiteScriptsDir = builtins.path { proxySuiteScriptsDir = import ../lib/scripts-dir.nix { inherit lib; };
name = "proxy-suite-scripts";
path = ../../../scripts;
};
parserScriptsPythonPath = proxySuiteScriptsDir; parserScriptsPythonPath = proxySuiteScriptsDir;
buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py"; buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py";
buildInboundPy = "${proxySuiteScriptsDir}/build-inbound.py"; buildInboundPy = "${proxySuiteScriptsDir}/build-inbound.py";
@@ -94,36 +52,38 @@ let
polkit = import ./polkit.nix { inherit userControlCfg; }; polkit = import ./polkit.nix { inherit userControlCfg; };
scripts = import ./scripts.nix { # One context for the service layer: everything derived.nix computes, the tool paths and
# generated files above, and the shell-snippet builders. Sub-modules take it whole and
# `inherit` the names they use, so adding a value needs no plumbing in between.
ctx = derived // {
inherit inherit
lib lib
pkgs pkgs
singBoxCfg packages
proxyCfg cfg
sshProxyCfg builders
warpCfg polkit
torCfg
awgOutbounds
xrayEnabled
hybridEnabled
pureXrayEnabled
activeBackend
perAppRoutingCfg
userControlCfg
selectionMode
collapseNamedOutbounds
constants
zapretCutoffProxyFallback
; ;
inherit inherit
jq jq
python3 python3
singBox singBox
xray xray
grepBin
awk
sleepBin
headBin
seqBin
findBin
awgBin
;
inherit
proxySuiteScriptsDir
parserScriptsPythonPath parserScriptsPythonPath
buildOutboundPy buildOutboundPy
buildInboundPy buildInboundPy
fetchSubscriptionPy fetchSubscriptionPy
amneziaWgProfileNamesFile
; ;
inherit inherit
tproxyFile tproxyFile
@@ -132,102 +92,28 @@ let
routeModeRulesFile routeModeRulesFile
proxyInboundsFile proxyInboundsFile
proxyInboundsSpecFile proxyInboundsSpecFile
perAppTunChainFile
perAppTproxyRulesFile
perAppZapretRulesFile
nftablesRulesFile
ip
nft
; ;
inherit # Filled in below; lazily, so the sub-modules can read each other's results.
proxyInboundsCfg inherit scripts perAppRouting;
proxyInboundsAwg
awgBin
proxyInboundsNeedLocalProxy
torOnionEnabled
proxyInboundsGuardPrivate
proxyInboundViaOutbounds
userControlAllows
builders
;
}; };
perAppRouting = import ./per-app-routing.nix { scripts = import ./scripts.nix { inherit ctx; };
inherit perAppRouting = import ./per-app-routing.nix { inherit ctx; };
lib control = import ./control.nix { inherit ctx; };
pkgs
cfg
singBoxCfg
proxyCfg
perAppRoutingCfg
perAppRoutingTun
perAppRoutingTproxy
constants
;
perAppZapretCfg = perAppZapretCfg;
inherit perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile;
inherit ip nft;
inherit
awk
grepBin
findBin
headBin
seqBin
sleepBin
;
};
control = import ./control.nix {
inherit
packages
singBoxCfg
proxyCfg
perAppRoutingCfg
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
zapretEngine
zapretCutoffEnabled
constants
selectionMode
userControlCfg
;
inherit (scripts) subscriptionTagsFile subscriptionCacheDir;
inherit (scripts) routeModeStateFile;
inherit proxyInboundsEnabled;
inherit (scripts) proxyInboundsLinksFile proxyInboundsSubscriptionsFile;
proxyInboundsSubscriptionsBaseUrl = proxyInboundsCfg.subscriptions.baseUrl;
proxyInboundsXray = "${proxyInboundsCfg.package}/bin/xray";
inherit amneziaWgProfileNamesFile;
guiRefreshInterval = cfg.gui.refreshInterval;
inherit (perAppRouting)
perAppRoutingProfilesFile
proxychainsConfigFile
proxychainsQuietArg
;
};
in in
{ {
inherit inherit
ctx
derived derived
singBoxCfg
proxyCfg
xrayCfg
proxyEnabled
singBoxEnabled
xrayEnabled
hybridEnabled
pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
globalTproxy
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
userControlCfg
builtinTags
outboundTags
subscriptionTags
invalidRoutingTargets
polkit polkit
scripts scripts
perAppRouting perAppRouting
control control
amneziaWgProfileNamesFile
; ;
} }
@@ -52,15 +52,7 @@ let
mode="''${1:-}" mode="''${1:-}"
case "$mode" in case "$mode" in
default) default | whitelist | blacklist | all-proxy | all-bypass)
;;
whitelist)
;;
blacklist)
;;
all-proxy)
;;
all-bypass)
;; ;;
*) *)
echo "proxy-suite: route mode must be default, whitelist, blacklist, all-proxy, or all-bypass" >&2 echo "proxy-suite: route mode must be default, whitelist, blacklist, all-proxy, or all-bypass" >&2
+86 -64
View File
@@ -1,75 +1,97 @@
# Builds proxy-ctl from global proxy-suite state and per-app routing metadata. # Builds proxy-ctl from global proxy-suite state and per-app routing metadata.
{ { ctx }:
packages,
singBoxCfg, let
proxyCfg, inherit (ctx)
perAppRoutingCfg, lib
perAppRoutingTun, localProxy
perAppRoutingTproxy, packages
perAppZapretCfg, cfg
zapretEngine, singBoxCfg
zapretCutoffEnabled, proxyCfg
constants, perAppRoutingCfg
selectionMode, perAppRoutingTun
userControlCfg, perAppRoutingTproxy
subscriptionTagsFile, perAppZapretCfg
subscriptionCacheDir, zapretEngine
perAppRoutingProfilesFile, zapretCutoffEnabled
proxychainsConfigFile, constants
proxychainsQuietArg, selectionMode
routeModeStateFile, userControlCfg
amneziaWgProfileNamesFile, proxyInboundsCfg
proxyInboundsEnabled, proxyInboundsEnabled
proxyInboundsLinksFile, amneziaWgProfileNamesFile
proxyInboundsSubscriptionsFile, ;
proxyInboundsSubscriptionsBaseUrl, inherit (ctx.scripts)
proxyInboundsXray, subscriptionTagsFile
guiRefreshInterval, subscriptionCacheDir
}: routeModeStateFile
proxyInboundsLinksFile
proxyInboundsSubscriptionsFile
;
inherit (ctx.perAppRouting)
perAppRoutingProfilesFile
proxychainsConfigFile
proxychainsQuietArg
;
proxyInboundsSubscriptionsBaseUrl = proxyInboundsCfg.subscriptions.baseUrl;
proxyInboundsXray = "${proxyInboundsCfg.package}/bin/xray";
guiRefreshInterval = cfg.gui.refreshInterval;
# proxy_ctl.py reads these as "1"/"0" strings.
flag = enabled: if enabled then "1" else "0";
in
{ {
proxyCtl = packages.mkProxyCtl { proxyCtl = packages.mkProxyCtl {
clashApi = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
selection = selectionMode;
inherit inherit
guiRefreshInterval
subscriptionTagsFile subscriptionTagsFile
subscriptionCacheDir
perAppRoutingProfilesFile perAppRoutingProfilesFile
proxychainsConfigFile proxychainsConfigFile
proxychainsQuietArg
routeModeStateFile
amneziaWgProfileNamesFile amneziaWgProfileNamesFile
guiRefreshInterval
; ;
defaultRouteMode = if (proxyCfg.routing.default == "proxy") then "blacklist" else "whitelist"; env = {
perAppRoutingEnabled = if perAppRoutingCfg.enable then "1" else "0"; CLASH_API = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
perAppRoutingProxychainsEnabled = if perAppRoutingCfg.proxychains.enable then "1" else "0"; SELECTION = selectionMode;
perAppRoutingTunEnabled = if perAppRoutingTun.enable then "1" else "0"; SUB_TAGS_FILE = toString subscriptionTagsFile;
perAppRoutingTproxyEnabled = if perAppRoutingTproxy.enable then "1" else "0"; SUB_CACHE_DIR = subscriptionCacheDir;
perAppRoutingZapretEnabled = if perAppZapretCfg.enable then "1" else "0"; PER_APP_ROUTING_ENABLED = flag perAppRoutingCfg.enable;
zapretAutoEnabled = if zapretEngine == "zapret2" then "1" else "0"; PER_APP_ROUTING_PROXYCHAINS_ENABLED = flag perAppRoutingCfg.proxychains.enable;
zapretStateDir = constants.zapret2StateDir; PER_APP_ROUTING_TUN_ENABLED = flag perAppRoutingTun.enable;
zapretCutoffEnabled = if zapretCutoffEnabled then "1" else "0"; PER_APP_ROUTING_TPROXY_ENABLED = flag perAppRoutingTproxy.enable;
outboundInventoryFile = constants.outboundInventoryFile; PER_APP_ROUTING_ZAPRET_ENABLED = flag perAppZapretCfg.enable;
runtimeOutboundsDir = constants.runtimeOutboundsDir; PER_APP_ROUTING_PROFILES_FILE = toString perAppRoutingProfilesFile;
runtimeSubscriptionsDir = constants.runtimeSubscriptionsDir; PROXYCHAINS_CONFIG = toString proxychainsConfigFile;
userControlGroup = userControlCfg.group; PROXYCHAINS_QUIET_ARG = lib.removeSuffix " " proxychainsQuietArg;
inboundsEnabled = if proxyInboundsEnabled then "1" else "0"; ROUTE_MODE_STATE_FILE = routeModeStateFile;
inboundsLinksFile = proxyInboundsLinksFile; DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
inboundsStatsFile = constants.inboundStatsFile; AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
inboundsXray = proxyInboundsXray; INBOUNDS_ENABLED = flag proxyInboundsEnabled;
inboundsApi = "127.0.0.1:${toString constants.inboundStatsApiPort}"; INBOUNDS_LINKS_FILE = proxyInboundsLinksFile;
inboundsSubscriptionsFile = proxyInboundsSubscriptionsFile; INBOUNDS_STATS_FILE = constants.inboundStatsFile;
inboundsSubscriptionsBaseUrl = INBOUNDS_XRAY = proxyInboundsXray;
if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl; INBOUNDS_API = "127.0.0.1:${toString constants.inboundStatsApiPort}";
autoProxyEnabled = if proxyCfg.autoProxy.enable then "1" else "0"; INBOUNDS_SUBS_FILE = proxyInboundsSubscriptionsFile;
autoProxyStateDir = constants.autoProxyStateDir; INBOUNDS_SUB_BASE_URL =
torControlSocket = constants.torControlSocket; if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl;
inherit (constants) stateDir runtimeDir serviceManager; ZAPRET_AUTO_ENABLED = flag (zapretEngine == "zapret2");
privileged = if constants.privileged then "1" else "0"; ZAPRET_STATE_DIR = constants.zapret2StateDir;
supervisorCtl = if constants.serviceManager == "supervisor" then constants.systemctl else ""; ZAPRET_CUTOFF_ENABLED = flag zapretCutoffEnabled;
singBox = "${singBoxCfg.package}/bin/sing-box"; OUTBOUND_INVENTORY_FILE = constants.outboundInventoryFile;
localProxyUrl = "http://${ RUNTIME_OUTBOUNDS_DIR = constants.runtimeOutboundsDir;
if proxyCfg.listener.address == "0.0.0.0" then "127.0.0.1" else proxyCfg.listener.address RUNTIME_SUBS_DIR = constants.runtimeSubscriptionsDir;
}:${toString proxyCfg.listener.port}"; USER_CONTROL_GROUP = userControlCfg.group;
LOCAL_PROXY_URL = "http://${localProxy.hostPart}:${toString proxyCfg.listener.port}";
AUTOPROXY_ENABLED = flag proxyCfg.autoProxy.enable;
AUTOPROXY_STATE_DIR = constants.autoProxyStateDir;
TOR_CONTROL_SOCKET = constants.torControlSocket;
SING_BOX = "${singBoxCfg.package}/bin/sing-box";
STATE_DIR = constants.stateDir;
RUNTIME_DIR = constants.runtimeDir;
SERVICE_MANAGER = constants.serviceManager;
PRIVILEGED = flag constants.privileged;
}
// lib.optionalAttrs (constants.serviceManager == "supervisor") {
SUPERVISOR_CTL = constants.systemctl;
};
}; };
} }
+5 -71
View File
@@ -3,43 +3,11 @@
{ {
lib, lib,
pkgs, pkgs,
packages,
cfg, cfg,
tproxyFile, context,
tunFile,
perAppTunFile,
routeModeRulesFile,
proxyInboundsFile,
proxyInboundsSpecFile,
nftablesRulesFile,
perAppTproxyRulesFile,
perAppZapretRulesFile,
perAppTunChainFile,
ip,
nft,
}: }:
let let
context = import ./context.nix {
inherit
lib
pkgs
packages
cfg
tproxyFile
tunFile
perAppTunFile
routeModeRulesFile
proxyInboundsFile
proxyInboundsSpecFile
perAppTunChainFile
perAppTproxyRulesFile
perAppZapretRulesFile
ip
nft
;
};
builders = import ./builders.nix { inherit lib pkgs; }; builders = import ./builders.nix { inherit lib pkgs; };
inherit (builders) mkNamedUnits; inherit (builders) mkNamedUnits;
@@ -79,46 +47,12 @@ let
builtinTags builtinTags
; ;
constants = derived.constants; constants = derived.constants;
routingScripts = import ./routing-scripts.nix { routingScripts = import ./routing-scripts.nix { inherit (context) ctx; };
inherit
lib
pkgs
builders
ip
nft
nftablesRulesFile
constants
globalTun
globalTproxy
perAppRoutingTun
;
inherit (proxyCfg) ipv6;
};
serviceUnits = import ./units.nix { serviceUnits = import ./units.nix {
inherit ctx = context.ctx // {
lib inherit routingScripts;
builders };
proxyCfg
proxyEnabled
hybridEnabled
pureXrayEnabled
globalTun
globalTproxy
perAppRoutingTun
perAppRoutingTproxy
perAppZapretEnabled
sshProxyOutboundEnabled
sshProxyUnitEnabled
torOutboundEnabled
torOnionEnabled
proxyInboundsEnabled
proxyInboundsNeedLocalProxy
scripts
perAppRouting
routingScripts
;
inherit (cfg) geodata;
}; };
inherit (serviceUnits) inherit (serviceUnits)
localProxyAuthEnabled localProxyAuthEnabled
+38 -126
View File
@@ -1,135 +1,47 @@
# App routing backend infrastructure (TUN, TProxy, zapret). # App routing backend infrastructure (TUN, TProxy, zapret).
{ { ctx }:
lib,
pkgs,
cfg,
singBoxCfg,
proxyCfg,
perAppRoutingCfg,
perAppRoutingTun,
perAppRoutingTproxy,
constants,
perAppZapretCfg,
perAppTunChainFile,
perAppTproxyRulesFile,
perAppZapretRulesFile,
ip,
nft,
awk,
grepBin,
findBin,
headBin,
seqBin,
sleepBin,
}:
let let
builders = import ./builders.nix { inherit lib pkgs; }; inherit (ctx)
inherit (builders) mkAnchorService; builders
nft
perAppTunSliceName = "proxy-suite-per-app-tun.slice"; awk
perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice"; grepBin
perAppZapretSliceName = "proxy-suite-per-app-zapret.slice"; findBin
headBin
profiles = import ./per-app-routing/profiles.nix { perAppRoutingTun
inherit (constants) runtimeDir; perAppRoutingTproxy
inherit perAppZapretCfg
lib
pkgs
proxyCfg
perAppRoutingCfg
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
;
};
inherit (profiles)
effectivePerAppRoutingProfiles
effectivePerAppRoutingProfileNames
perAppRoutingProfilesFile
proxychainsConfigFile
proxychainsQuietArg
hasProxychainsProfiles
hasTunProfiles
hasTproxyProfiles
hasZapretProfiles
; ;
backendScripts = import ./per-app-routing/backend-scripts.nix { slices = {
inherit perAppTunSliceName = "proxy-suite-per-app-tun.slice";
lib perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice";
pkgs perAppZapretSliceName = "proxy-suite-per-app-zapret.slice";
builders
perAppRoutingTun
perAppRoutingTproxy
constants
perAppTunChainFile
perAppTproxyRulesFile
ip
nft
seqBin
sleepBin
;
inherit (proxyCfg) ipv6;
}; };
inherit (backendScripts)
perAppTunUpScript
perAppTunDownScript
perAppTproxyUpScript
perAppTproxyDownScript
;
userRules = import ./per-app-routing/user-rules.nix {
inherit
lib
pkgs
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
perAppTunSliceName
perAppTproxySliceName
perAppZapretSliceName
nft
awk
grepBin
findBin
headBin
;
};
inherit (userRules)
perAppTunUserRuleStart
perAppTunUserRuleStop
perAppTproxyUserRuleStart
perAppTproxyUserRuleStop
perAppZapretUserRuleStart
perAppZapretUserRuleStop
;
# user-rules.nix is also imported by the checks, so it keeps an explicit argument list.
userRules = import ./per-app-routing/user-rules.nix (
{
inherit (ctx) lib pkgs;
inherit
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
nft
awk
grepBin
findBin
headBin
;
}
// slices
);
in in
{ slices
inherit // import ./per-app-routing/profiles.nix { inherit ctx; }
perAppTunSliceName // import ./per-app-routing/backend-scripts.nix { inherit ctx; }
perAppTproxySliceName // userRules
perAppZapretSliceName // {
perAppTunUpScript inherit (builders) mkAnchorService;
perAppTunDownScript
perAppTproxyUpScript
perAppTproxyDownScript
perAppTunUserRuleStart
perAppTunUserRuleStop
perAppTproxyUserRuleStart
perAppTproxyUserRuleStop
perAppZapretUserRuleStart
perAppZapretUserRuleStop
mkAnchorService
effectivePerAppRoutingProfiles
effectivePerAppRoutingProfileNames
perAppRoutingProfilesFile
proxychainsConfigFile
proxychainsQuietArg
hasProxychainsProfiles
hasTunProfiles
hasTproxyProfiles
hasZapretProfiles
;
} }
@@ -1,21 +1,23 @@
# Per-app TUN and TProxy backend lifecycle scripts. # Per-app TUN and TProxy backend lifecycle scripts.
{ { ctx }:
lib,
pkgs,
builders,
perAppRoutingTun,
perAppRoutingTproxy,
ipv6,
constants,
perAppTunChainFile,
perAppTproxyRulesFile,
ip,
nft,
seqBin,
sleepBin,
}:
let let
inherit (ctx)
lib
pkgs
builders
perAppRoutingTun
perAppRoutingTproxy
proxyCfg
constants
perAppTunChainFile
perAppTproxyRulesFile
ip
nft
seqBin
sleepBin
;
inherit (proxyCfg) ipv6;
inherit (constants) inherit (constants)
perAppTunIPv6Address perAppTunIPv6Address
perAppTunIPv6RoutePrefix perAppTunIPv6RoutePrefix
@@ -1,16 +1,18 @@
# Per-app routing profile expansion and proxychains config. # Per-app routing profile expansion and proxychains config.
{ { ctx }:
lib,
pkgs,
proxyCfg,
perAppRoutingCfg,
perAppRoutingTun,
perAppRoutingTproxy,
perAppZapretCfg,
runtimeDir,
}:
let let
inherit (ctx)
lib
pkgs
proxyCfg
perAppRoutingCfg
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
constants
;
inherit (constants) runtimeDir;
perAppRoutingProfileNames = map (profile: profile.name) perAppRoutingCfg.profiles; perAppRoutingProfileNames = map (profile: profile.name) perAppRoutingCfg.profiles;
defaultPerAppRoutingProfiles = lib.optionals perAppRoutingCfg.createDefaultProfiles ( defaultPerAppRoutingProfiles = lib.optionals perAppRoutingCfg.createDefaultProfiles (
[ [
@@ -46,9 +48,7 @@ let
effectivePerAppRoutingProfileNames = map (profile: profile.name) effectivePerAppRoutingProfiles; effectivePerAppRoutingProfileNames = map (profile: profile.name) effectivePerAppRoutingProfiles;
localProxyAuth = proxyCfg.listener.auth; localProxyAuth = proxyCfg.listener.auth;
localProxyAuthEnabled = localProxyAuthEnabled = ctx.localProxy.authEnabled;
localProxyAuth.username != null
&& (localProxyAuth.password != null || localProxyAuth.passwordFile != null);
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app" ( perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app" (
builtins.toJSON effectivePerAppRoutingProfiles builtins.toJSON effectivePerAppRoutingProfiles
@@ -1,32 +1,33 @@
# Start script of the inbound service: renders the listeners with their secrets into the # Start script of the inbound service: renders the listeners with their secrets into the
# template and runs XRay. # template and runs XRay.
{ { ctx }:
lib,
pkgs,
proxyCfg,
proxyInboundsCfg,
proxyInboundsAwg,
awgBin,
proxyInboundsNeedLocalProxy,
torOnionEnabled,
proxyInboundViaOutbounds,
userControlCfg,
userControlAllows,
localProxyAuth,
localProxyAuthEnabled,
localProxyAuthPasswordSource,
jq,
python3,
parserScriptsPythonPath,
buildInboundPy,
buildOutboundPy,
proxyInboundsFile,
proxyInboundsSpecFile,
builders,
constants,
}:
let let
inherit (ctx)
lib
pkgs
proxyCfg
proxyInboundsCfg
proxyInboundsAwg
awgBin
proxyInboundsNeedLocalProxy
torOnionEnabled
proxyInboundViaOutbounds
userControlCfg
userControlAllows
localProxyAuth
localProxyAuthEnabled
localProxyAuthPasswordSource
jq
python3
parserScriptsPythonPath
buildInboundPy
buildOutboundPy
proxyInboundsFile
proxyInboundsSpecFile
builders
constants
;
runtimeDir = "${constants.runtimeDir}/proxy-suite-inbounds"; runtimeDir = "${constants.runtimeDir}/proxy-suite-inbounds";
linksFile = "${runtimeDir}/links.json"; linksFile = "${runtimeDir}/links.json";
subscriptionsFile = "${runtimeDir}/subscriptions.json"; subscriptionsFile = "${runtimeDir}/subscriptions.json";
+15 -13
View File
@@ -1,18 +1,20 @@
{ { ctx }:
lib,
pkgs,
builders,
ip,
nft,
nftablesRulesFile,
constants,
globalTun,
globalTproxy,
perAppRoutingTun,
ipv6,
}:
let let
inherit (ctx)
lib
pkgs
builders
ip
nft
nftablesRulesFile
constants
globalTun
globalTproxy
perAppRoutingTun
proxyCfg
;
inherit (proxyCfg) ipv6;
inherit (constants) inherit (constants)
tunAutoRouteTableIndex tunAutoRouteTableIndex
tunAutoRouteRulePriority tunAutoRouteRulePriority
@@ -1,9 +1,13 @@
{ { ctx }:
lib,
jq, let
hybridEnabled, inherit (ctx)
xraySidecarRoutingMark, lib
}: jq
hybridEnabled
xraySidecarRoutingMark
;
in
routingMark: xraySidecarBasePort: xrayDnsBridgePort: routingMark: xraySidecarBasePort: xrayDnsBridgePort:
@@ -3,23 +3,24 @@
# Everything is emitted as shell functions taking a tag and a file holding the # Everything is emitted as shell functions taking a tag and a file holding the
# subscription URL, so a subscription declared in Nix and one added at runtime # subscription URL, so a subscription declared in Nix and one added at runtime
# under `subscriptions.d/` go through exactly the same code. # under `subscriptions.d/` go through exactly the same code.
{ { ctx }:
lib,
pkgs,
proxyCfg,
hybridEnabled,
mainBackend,
backend,
stateDir,
runtimeSubscriptionsDir,
jq,
python3,
parserScriptsPythonPath,
fetchSubscriptionPy,
routingMarkJq,
}:
let let
inherit (ctx)
lib
pkgs
proxyCfg
hybridEnabled
mainBackend
backend
constants
jq
python3
parserScriptsPythonPath
fetchSubscriptionPy
routingMarkJq
;
inherit (constants) stateDir runtimeSubscriptionsDir;
subscriptionBackend = if hybridEnabled then "hybrid" else mainBackend; subscriptionBackend = if hybridEnabled then "hybrid" else mainBackend;
subscriptionBackendArg = "--backend ${subscriptionBackend}"; subscriptionBackendArg = "--backend ${subscriptionBackend}";
subscriptionCacheDir = "${stateDir}/subscriptions/${backend}"; subscriptionCacheDir = "${stateDir}/subscriptions/${backend}";
+66 -131
View File
@@ -1,49 +1,36 @@
# Assembles proxy backend startup and control scripts. # Assembles proxy backend startup and control scripts.
{ { ctx }:
lib,
pkgs,
singBoxCfg,
proxyCfg,
sshProxyCfg,
warpCfg,
torCfg,
awgOutbounds,
xrayEnabled,
hybridEnabled,
pureXrayEnabled,
activeBackend,
perAppRoutingCfg,
userControlCfg,
selectionMode,
collapseNamedOutbounds,
constants,
zapretCutoffProxyFallback,
jq,
python3,
singBox,
xray,
parserScriptsPythonPath,
buildOutboundPy,
fetchSubscriptionPy,
tproxyFile,
tunFile,
perAppTunFile,
routeModeRulesFile,
proxyInboundsCfg,
proxyInboundsAwg,
awgBin,
proxyInboundsNeedLocalProxy,
torOnionEnabled,
proxyInboundsGuardPrivate,
proxyInboundViaOutbounds,
userControlAllows,
buildInboundPy,
proxyInboundsFile,
proxyInboundsSpecFile,
builders,
}:
let let
inherit (ctx)
lib
pkgs
singBoxCfg
proxyCfg
activeBackend
xrayEnabled
hybridEnabled
pureXrayEnabled
perAppRoutingCfg
userControlCfg
userControlAllows
selectionMode
constants
zapretCutoffProxyFallback
jq
python3
singBox
xray
proxyInboundsCfg
proxyInboundsGuardPrivate
routeModeRulesFile
tproxyFile
tunFile
perAppTunFile
proxyInboundsFile
proxyInboundsSpecFile
builders
;
globalTproxy = proxyCfg.tproxy; globalTproxy = proxyCfg.tproxy;
backend = if activeBackend == null then "sing-box" else activeBackend; backend = if activeBackend == null then "sing-box" else activeBackend;
mainBackend = if pureXrayEnabled then "xray" else "sing-box"; mainBackend = if pureXrayEnabled then "xray" else "sing-box";
@@ -81,23 +68,43 @@ let
else else
" | .routing_mark = ${toString routingMark}"; " | .routing_mark = ${toString routingMark}";
subscriptionScripts = import ./script-blocks/subscriptions.nix { # ctx plus this layer's own values; the script blocks read what they need off it. Lazy, so
inherit (constants) stateDir; # a block may use a sibling's output (start-scripts uses the subscription helpers).
sctx = ctx // {
inherit inherit
lib
pkgs
proxyCfg
hybridEnabled
mainBackend
backend backend
runtimeSubscriptionsDir mainBackend
jq backendArg
python3 backendBin
parserScriptsPythonPath globalTproxy
fetchSubscriptionPy localProxyAuth
localProxyAuthEnabled
localProxyAuthPasswordSource
routeModeStateFile
xrayLoglevelFile
runtimeProxychainsConfig
xraySidecarRoutingMark
routingMarkJq routingMarkJq
pinnedOutboundFile
runtimeOutboundsDir
runtimeSubscriptionsDir
outboundInventoryFile
clashApi
; ;
inherit (subscriptionScripts)
subscriptionCacheDir
subscriptionCacheHelpersBlock
mkSubscriptionLoadHelperBlock
mkSubscriptionBlock
runtimeSubscriptionsBlock
mkSubscriptionFetchBlock
runtimeSubscriptionsFetchBlock
;
inherit (outboundScripts) mkOutboundScript;
inherit hybridRuntimeHelpersBlock backendJqFilterFile;
}; };
subscriptionScripts = import ./script-blocks/subscriptions.nix { ctx = sctx; };
inherit (subscriptionScripts) inherit (subscriptionScripts)
subscriptionCacheDir subscriptionCacheDir
subscriptionCacheHelpersBlock subscriptionCacheHelpersBlock
@@ -110,7 +117,7 @@ let
; ;
outboundScripts = import ./script-blocks/outbounds.nix { outboundScripts = import ./script-blocks/outbounds.nix {
inherit inherit (sctx)
lib lib
pkgs pkgs
singBoxCfg singBoxCfg
@@ -140,14 +147,7 @@ let
}; };
inherit (outboundScripts) mkOutboundScript; inherit (outboundScripts) mkOutboundScript;
hybridRuntimeHelpersBlock = import ./script-blocks/hybrid-runtime-helpers.nix { hybridRuntimeHelpersBlock = import ./script-blocks/hybrid-runtime-helpers.nix { ctx = sctx; };
inherit
lib
jq
hybridEnabled
xraySidecarRoutingMark
;
};
backendJqFilter = import ./script-blocks/backend-jq-filter.nix { backendJqFilter = import ./script-blocks/backend-jq-filter.nix {
inherit inherit
@@ -160,69 +160,10 @@ let
}; };
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter; backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
startScripts = import ./start-scripts.nix { startScripts = import ./start-scripts.nix { ctx = sctx; };
inherit
lib
pkgs
proxyCfg
perAppRoutingCfg
userControlCfg
userControlAllows
globalTproxy
xrayEnabled
hybridEnabled
pureXrayEnabled
constants
zapretCutoffProxyFallback
jq
singBox
xray
backendBin
routeModeStateFile
routeModeRulesFile
xrayLoglevelFile
runtimeProxychainsConfig
localProxyAuth
localProxyAuthEnabled
localProxyAuthPasswordSource
backendJqFilterFile
hybridRuntimeHelpersBlock
subscriptionCacheHelpersBlock
mkOutboundScript
tproxyFile
tunFile
perAppTunFile
;
};
inherit (startScripts) startSocks startTun startPerAppTun; inherit (startScripts) startSocks startTun startPerAppTun;
proxyInboundsScripts = import ./proxy-inbounds-scripts.nix { proxyInboundsScripts = import ./proxy-inbounds-scripts.nix { ctx = sctx; };
inherit
lib
pkgs
proxyCfg
proxyInboundsCfg
proxyInboundsAwg
awgBin
proxyInboundsNeedLocalProxy
torOnionEnabled
proxyInboundViaOutbounds
userControlCfg
userControlAllows
localProxyAuth
localProxyAuthEnabled
localProxyAuthPasswordSource
jq
python3
parserScriptsPythonPath
buildInboundPy
buildOutboundPy
proxyInboundsFile
proxyInboundsSpecFile
builders
constants
;
};
inherit (proxyInboundsScripts) startInbounds collectInboundStats; inherit (proxyInboundsScripts) startInbounds collectInboundStats;
proxyInboundsLinksFile = proxyInboundsScripts.linksFile; proxyInboundsLinksFile = proxyInboundsScripts.linksFile;
proxyInboundsSubscriptionsFile = proxyInboundsScripts.subscriptionsFile; proxyInboundsSubscriptionsFile = proxyInboundsScripts.subscriptionsFile;
@@ -271,11 +212,5 @@ in
subscriptionUpdateScript subscriptionUpdateScript
subscriptionTagsFile subscriptionTagsFile
subscriptionCacheDir subscriptionCacheDir
runtimeProxychainsConfig
pinnedOutboundFile
runtimeOutboundsDir
runtimeSubscriptionsDir
outboundInventoryFile
clashApi
; ;
} }
+112 -84
View File
@@ -1,38 +1,39 @@
# Backend startup script derivations. # Backend startup script derivations.
{ { ctx }:
lib,
pkgs,
proxyCfg,
perAppRoutingCfg,
userControlCfg,
userControlAllows,
globalTproxy,
xrayEnabled,
hybridEnabled,
pureXrayEnabled,
constants,
zapretCutoffProxyFallback,
jq,
singBox,
xray,
backendBin,
routeModeStateFile,
routeModeRulesFile,
xrayLoglevelFile,
runtimeProxychainsConfig,
localProxyAuth,
localProxyAuthEnabled,
localProxyAuthPasswordSource,
backendJqFilterFile,
hybridRuntimeHelpersBlock,
subscriptionCacheHelpersBlock,
mkOutboundScript,
tproxyFile,
tunFile,
perAppTunFile,
}:
let let
inherit (ctx)
lib
pkgs
proxyCfg
perAppRoutingCfg
userControlCfg
userControlAllows
globalTproxy
xrayEnabled
hybridEnabled
pureXrayEnabled
constants
zapretCutoffProxyFallback
jq
singBox
xray
backendBin
routeModeStateFile
routeModeRulesFile
xrayLoglevelFile
runtimeProxychainsConfig
localProxyAuth
localProxyAuthEnabled
localProxyAuthPasswordSource
backendJqFilterFile
hybridRuntimeHelpersBlock
subscriptionCacheHelpersBlock
mkOutboundScript
tproxyFile
tunFile
perAppTunFile
;
inherit (constants) inherit (constants)
autoProxyStateDir autoProxyStateDir
outboundTestPort outboundTestPort
@@ -60,62 +61,89 @@ let
+ .proxyGeo + .proxyGeo
''; '';
# Every route mode is the same four assignments over one jq program on the rule buckets.
routeModeArms = [
{
mode = "blacklist";
final = "proxy";
dns = "remote";
rules = ''
.common
+ (.custom | map(.entries) | add // [])
+ .proxyPrimary
+ .direct
+ .safetyDirect
${routeModeBlacklistTail}
'';
}
{
mode = "whitelist";
final = "direct";
dns = "local";
rules = ''
.common
+ (.custom | map(.entries) | add // [])
+ .proxyPrimary
+ .direct
+ .safetyDirect
${routeModeBlacklistTail}
'';
}
{
# Only the proxy and block lists are kept: everything else follows the final action.
mode = "all-proxy";
final = "proxy";
dns = "remote";
clearDns = true;
rules = ''
.common
+ (.custom | map(select(.category == "proxy" or .category == "block") | .entries) | add // [])
+ .proxyPrimary
+ .safetyDirect
${routeModeBlacklistTail}
'';
}
{
mode = "all-bypass";
final = "direct";
dns = "local";
clearDns = true;
rules = ''
.common
+ (.custom | map(select(.category == "block") | .entries) | add // [])
+ .safetyDirect
+ .block
'';
}
];
# Written out line by line: the block lands inside a `case`, where the indentation of an
# interpolated multi-line value would otherwise be lost.
mkRouteModeArm =
arm:
lib.concatStringsSep "\n" (
[
" ${arm.mode})"
" ROUTE_FINAL=\"${arm.final}\""
" DNS_FINAL=\"${arm.dns}\""
" ROUTE_MODE_ACTIVE=true"
]
++ lib.optional (arm.clearDns or false) " CLEAR_DNS_RULES=true"
++ [ " ROUTE_RULES_JSON=$(${jq} -c '" ]
++ map (line: if line == "" then "" else " ${line}") (
lib.splitString "\n" (lib.removeSuffix "\n" arm.rules)
)
++ [
" ' \"${routeModeRulesFile}\")"
" ;;"
]
);
routeModeCaseBlock = '' routeModeCaseBlock = ''
if [ -r "$ROUTE_MODE_STATE_FILE" ]; then if [ -r "$ROUTE_MODE_STATE_FILE" ]; then
ROUTE_MODE="$(tr -d '\r\n[:space:]' < "$ROUTE_MODE_STATE_FILE" 2>/dev/null || true)" ROUTE_MODE="$(tr -d '\r\n[:space:]' < "$ROUTE_MODE_STATE_FILE" 2>/dev/null || true)"
fi fi
case "$ROUTE_MODE" in case "$ROUTE_MODE" in${lib.concatMapStrings (arm: "\n" + mkRouteModeArm arm) routeModeArms}
blacklist)
ROUTE_FINAL="proxy"
DNS_FINAL="remote"
ROUTE_MODE_ACTIVE=true
ROUTE_RULES_JSON=$(${jq} -c '
.common
+ (.custom | map(.entries) | add // [])
+ .proxyPrimary
+ .direct
+ .safetyDirect
${routeModeBlacklistTail}
' "${routeModeRulesFile}")
;;
whitelist)
ROUTE_FINAL="direct"
DNS_FINAL="local"
ROUTE_MODE_ACTIVE=true
ROUTE_RULES_JSON=$(${jq} -c '
.common
+ (.custom | map(.entries) | add // [])
+ .proxyPrimary
+ .direct
+ .safetyDirect
${routeModeBlacklistTail}
' "${routeModeRulesFile}")
;;
all-proxy)
ROUTE_FINAL="proxy"
DNS_FINAL="remote"
ROUTE_MODE_ACTIVE=true
CLEAR_DNS_RULES=true
ROUTE_RULES_JSON=$(${jq} -c '
.common
+ (.custom | map(select(.category == "proxy" or .category == "block") | .entries) | add // [])
+ .proxyPrimary
+ .safetyDirect
${routeModeBlacklistTail}
' "${routeModeRulesFile}")
;;
all-bypass)
ROUTE_FINAL="direct"
DNS_FINAL="local"
ROUTE_MODE_ACTIVE=true
CLEAR_DNS_RULES=true
ROUTE_RULES_JSON=$(${jq} -c '
.common
+ (.custom | map(select(.category == "block") | .entries) | add // [])
+ .safetyDirect
+ .block
' "${routeModeRulesFile}")
;;
*) *)
ROUTE_MODE="" ROUTE_MODE=""
;; ;;
+26 -27
View File
@@ -1,29 +1,31 @@
# Systemd unit definitions for proxy-suite services and timers. # Systemd unit definitions for proxy-suite services and timers.
{ { ctx }:
lib,
builders,
proxyCfg,
proxyEnabled,
hybridEnabled,
pureXrayEnabled,
globalTun,
globalTproxy,
perAppRoutingTun,
perAppRoutingTproxy,
perAppZapretEnabled,
sshProxyOutboundEnabled,
sshProxyUnitEnabled,
torOutboundEnabled,
torOnionEnabled,
proxyInboundsEnabled,
proxyInboundsNeedLocalProxy,
scripts,
perAppRouting,
routingScripts,
geodata,
}:
let let
inherit (ctx)
lib
builders
proxyCfg
proxyEnabled
hybridEnabled
pureXrayEnabled
globalTun
globalTproxy
perAppRoutingTun
perAppRoutingTproxy
perAppZapretEnabled
sshProxyOutboundEnabled
sshProxyUnitEnabled
torOutboundEnabled
torOnionEnabled
proxyInboundsEnabled
proxyInboundsNeedLocalProxy
scripts
perAppRouting
routingScripts
cfg
;
inherit (cfg) geodata;
inherit (builders) inherit (builders)
mkAnchorService mkAnchorService
mkRestartingService mkRestartingService
@@ -58,9 +60,7 @@ let
else else
"sing-box"; "sing-box";
localProxyAuthEnabled = localProxyAuthEnabled = ctx.localProxy.authEnabled;
proxyCfg.listener.auth.username != null
&& (proxyCfg.listener.auth.password != null || proxyCfg.listener.auth.passwordFile != null);
# XRay finds geoip.dat/geosite.dat through this; sing-box ignores it. # XRay finds geoip.dat/geosite.dat through this; sing-box ignores it.
xrayAssetEnv = lib.optionalAttrs (geodata.xray.assets != null) { xrayAssetEnv = lib.optionalAttrs (geodata.xray.assets != null) {
@@ -336,7 +336,6 @@ let
in in
{ {
inherit inherit
serviceNames
localProxyAuthEnabled localProxyAuthEnabled
systemServiceEntries systemServiceEntries
userServiceEntries userServiceEntries
+4 -14
View File
@@ -12,20 +12,10 @@ let
inherit (derived.constants) unprivilegedServiceConfig; inherit (derived.constants) unprivilegedServiceConfig;
inherit (cfg.host) privileged; inherit (cfg.host) privileged;
inherit (derived.localProxy) auth;
listener = cfg.proxy.listener; listener = cfg.proxy.listener;
auth = listener.auth; proxyHost = derived.localProxy.host;
# Tor dials the local proxy by address: a wildcard listener is reached on loopback. proxyHostPart = derived.localProxy.hostPart;
proxyHost =
if
builtins.elem listener.address [
"0.0.0.0"
"::"
]
then
"127.0.0.1"
else
listener.address;
proxyHostPart = if lib.hasInfix ":" proxyHost then "[${proxyHost}]" else proxyHost;
passwordSource = passwordSource =
if auth.passwordFile != null then if auth.passwordFile != null then
auth.passwordFile auth.passwordFile
@@ -34,7 +24,7 @@ let
else else
null; null;
viaProxy = t.upstream == "proxy"; viaProxy = t.upstream == "proxy";
withProxyAuth = viaProxy && auth.username != null && passwordSource != null; withProxyAuth = viaProxy && derived.localProxy.authEnabled;
bridgesEnabled = t.bridges.lines != [ ] || t.bridges.file != null; bridgesEnabled = t.bridges.lines != [ ] || t.bridges.file != null;
# The control socket's directory: members of userControl.group may use it for # The control socket's directory: members of userControl.group may use it for
+2 -13
View File
@@ -10,19 +10,8 @@
let let
w = derived.warpCfg; w = derived.warpCfg;
inherit (derived.constants) unprivilegedServiceConfig; inherit (derived.constants) unprivilegedServiceConfig;
inherit (derived.localProxy) auth host hostPart;
listener = cfg.proxy.listener; listener = cfg.proxy.listener;
auth = listener.auth;
host =
if
builtins.elem listener.address [
"0.0.0.0"
"::"
]
then
"127.0.0.1"
else
listener.address;
hostPart = if lib.hasInfix ":" host then "[${host}]" else host;
passwordSource = passwordSource =
if auth.passwordFile != null then if auth.passwordFile != null then
auth.passwordFile auth.passwordFile
@@ -30,7 +19,7 @@ let
pkgs.writeText "proxy-suite-warp" auth.password pkgs.writeText "proxy-suite-warp" auth.password
else else
null; null;
withProxyAuth = auth.username != null && passwordSource != null; withProxyAuth = derived.localProxy.authEnabled;
userinfo = lib.optionalString withProxyAuth '' userinfo = lib.optionalString withProxyAuth ''
userinfo=$(${pkgs.jq}/bin/jq -rn --arg u ${lib.escapeShellArg auth.username} \ userinfo=$(${pkgs.jq}/bin/jq -rn --arg u ${lib.escapeShellArg auth.username} \
--rawfile p "$CREDENTIALS_DIRECTORY/proxy-password" '"\($u | @uri):\($p | rtrimstr("\n") | @uri)@"') --rawfile p "$CREDENTIALS_DIRECTORY/proxy-password" '"\($u | @uri):\($p | rtrimstr("\n") | @uri)@"')
+1 -4
View File
@@ -10,10 +10,7 @@
let let
inherit (derived.constants) serviceUser runAsServiceUser ifPrivileged; inherit (derived.constants) serviceUser runAsServiceUser ifPrivileged;
scriptsDir = builtins.path { scriptsDir = import ./lib/scripts-dir.nix { inherit lib; };
name = "proxy-suite-scripts";
path = ../../scripts;
};
# sing-box's "local" server has no upstream on hosts behind systemd-resolved, so the tunnel # sing-box's "local" server has no upstream on hosts behind systemd-resolved, so the tunnel
# resolves the peer hostname like the main config, with proxy.dns.local. Destinations are # resolves the peer hostname like the main config, with proxy.dns.local. Destinations are
+16 -20
View File
@@ -14,10 +14,21 @@ let
zapretCfg = cfg.zapret; zapretCfg = cfg.zapret;
perAppZapretCfg = cfg.perAppRouting.zapret; perAppZapretCfg = cfg.perAppRouting.zapret;
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone. inherit
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") ( (import ./zapret/common.nix {
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles) inherit
); lib
pkgs
cfg
nft
perAppZapretRulesFile
;
})
awgServiceNames
perAppConflicts
perAppZapretMarkUpScript
perAppZapretMarkDownScript
;
zapretPackages = import ./zapret/packages.nix { zapretPackages = import ./zapret/packages.nix {
inherit inherit
lib lib
@@ -47,17 +58,6 @@ let
fi fi
''; '';
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret" ''
set -euo pipefail
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
${nft} -f ${perAppZapretRulesFile}
'';
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret" ''
set -euo pipefail
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
'';
exemptStart = '' exemptStart = ''
set -euo pipefail set -euo pipefail
'' ''
@@ -108,11 +108,7 @@ in
description = "proxy-suite per-app-routing zapret backend"; description = "proxy-suite per-app-routing zapret backend";
after = [ "network-online.target" ]; after = [ "network-online.target" ];
wants = [ "network-online.target" ]; wants = [ "network-online.target" ];
conflicts = [ conflicts = perAppConflicts ++ awgServiceNames;
"proxy-suite-tproxy.service"
"proxy-suite-tun.service"
]
++ awgServiceNames;
preStart = zapretCommonPreStart perAppZapretPackage; preStart = zapretCommonPreStart perAppZapretPackage;
runtimeDirectory = "proxy-suite-per-app-zapret"; runtimeDirectory = "proxy-suite-per-app-zapret";
execStart = "${perAppZapretPackage}/opt/zapret/init.d/sysv/zapret start"; execStart = "${perAppZapretPackage}/opt/zapret/init.d/sysv/zapret start";
+42
View File
@@ -0,0 +1,42 @@
# What both zapret engines need the same way: which units they must not run beside, the
# interfaces to keep out of NFQUEUE, and the per-app mark table's nft hooks.
{
lib,
pkgs,
cfg,
nft ? null,
perAppZapretRulesFile ? null,
# zapret v1 names its scripts proxy-suite-zapret, zapret2 proxy-suite-zapret2.
scriptName ? "proxy-suite-zapret",
}:
let
dropMarkTable = "${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true";
in
{
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone.
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") (
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles)
);
tunInterfaces = lib.unique (
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
);
# The transparent backends steer the same packets; a per-app zapret instance replaces them.
perAppConflicts = [
"proxy-suite-tproxy.service"
"proxy-suite-tun.service"
];
perAppZapretMarkUpScript = pkgs.writeShellScript scriptName ''
set -euo pipefail
${dropMarkTable}
${nft} -f ${perAppZapretRulesFile}
'';
perAppZapretMarkDownScript = pkgs.writeShellScript scriptName ''
set -euo pipefail
${dropMarkTable}
'';
}
+2 -10
View File
@@ -9,10 +9,7 @@
let let
zapretCfg = cfg.zapret; zapretCfg = cfg.zapret;
perAppZapretCfg = cfg.perAppRouting.zapret; perAppZapretCfg = cfg.perAppRouting.zapret;
tunInterfaces = lib.unique ( inherit (import ./common.nix { inherit lib pkgs cfg; }) tunInterfaces;
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
);
zapretDomainGroups = import ../zapret-domain-groups.nix { inherit lib zapret; }; zapretDomainGroups = import ../zapret-domain-groups.nix { inherit lib zapret; };
runtimeDeps = lib.attrValues { runtimeDeps = lib.attrValues {
@@ -84,12 +81,7 @@ let
); );
selectedConfigName = lib.strings.sanitizeDerivationName zapretCfg.zapret-discord-youtube.configName; selectedConfigName = lib.strings.sanitizeDerivationName zapretCfg.zapret-discord-youtube.configName;
patchConfigScriptSrc = "${ patchConfigScriptSrc = "${import ../lib/scripts-dir.nix { inherit lib; }}/patch-zapret-config.py";
builtins.path {
name = "proxy-suite-scripts";
path = ../../../scripts;
}
}/patch-zapret-config.py";
patchConfigScript = "${pkgs.python3}/bin/python3 ${patchConfigScriptSrc}"; patchConfigScript = "${pkgs.python3}/bin/python3 ${patchConfigScriptSrc}";
packageBuilder = import ./package-builder.nix { packageBuilder = import ./package-builder.nix {
+18 -24
View File
@@ -17,10 +17,23 @@ let
perAppZapretCfg = cfg.perAppRouting.zapret; perAppZapretCfg = cfg.perAppRouting.zapret;
cutoffCfg = zapretCfg.zapret2.cutoff; cutoffCfg = zapretCfg.zapret2.cutoff;
inherit (import ./derived.nix { inherit lib cfg; }) constants userControlAllows; inherit (import ./derived.nix { inherit lib cfg; }) constants userControlAllows;
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone. inherit
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") ( (import ./zapret/common.nix {
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles) inherit
); lib
pkgs
cfg
nft
perAppZapretRulesFile
;
scriptName = "proxy-suite-zapret2";
})
awgServiceNames
tunInterfaces
perAppConflicts
perAppZapretMarkUpScript
perAppZapretMarkDownScript
;
runtime = import ./zapret2/runtime.nix { runtime = import ./zapret2/runtime.nix {
inherit inherit
@@ -32,11 +45,6 @@ let
; ;
}; };
tunInterfaces = lib.unique (
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
);
globalRuntime = runtime.mkRuntime { globalRuntime = runtime.mkRuntime {
name = "proxy-suite-zapret2"; name = "proxy-suite-zapret2";
qnum = constants.zapretGlobalQnum.zapret2; qnum = constants.zapretGlobalQnum.zapret2;
@@ -91,16 +99,6 @@ let
; ;
}; };
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
set -euo pipefail
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
${nft} -f ${perAppZapretRulesFile}
'';
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
set -euo pipefail
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
'';
in in
{ {
services.proxy-suite.internal.earlyPackages = [ runtime.package ]; services.proxy-suite.internal.earlyPackages = [ runtime.package ];
@@ -138,11 +136,7 @@ in
description = "proxy-suite per-app-routing zapret2 backend"; description = "proxy-suite per-app-routing zapret2 backend";
after = [ "network-online.target" ]; after = [ "network-online.target" ];
wants = [ "network-online.target" ]; wants = [ "network-online.target" ];
conflicts = [ conflicts = perAppConflicts ++ awgServiceNames;
"proxy-suite-tproxy.service"
"proxy-suite-tun.service"
]
++ awgServiceNames;
preStart = mkPreStart; preStart = mkPreStart;
runtimeDirectory = "proxy-suite-per-app-zapret"; runtimeDirectory = "proxy-suite-per-app-zapret";
stateDirectory = "proxy-suite"; stateDirectory = "proxy-suite";
+2 -2
View File
@@ -20,7 +20,7 @@ let
} }
); );
}; };
parserChecks = import ./checks/parsers.nix { inherit pkgs; }; pythonChecks = import ./checks/python-tests.nix { inherit pkgs; };
checkLib = import ./checks/lib.nix { checkLib = import ./checks/lib.nix {
inherit inherit
pkgs pkgs
@@ -67,5 +67,5 @@ moduleSuiteChecks
proxy-inbounds-runtime = proxyInboundsRuntime; proxy-inbounds-runtime = proxyInboundsRuntime;
amneziawg-inbounds-runtime = amneziaWgInboundsRuntime; amneziawg-inbounds-runtime = amneziaWgInboundsRuntime;
} }
// parserChecks // pythonChecks
// repoChecks // repoChecks
+12 -15
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkBadProxySuiteFixture, mkBadProxySuiteFixture,
@@ -9,6 +10,7 @@
}: }:
let let
inherit (checkLib) mkProxySuite;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
inherit (pkgs.lib) hasInfix; inherit (pkgs.lib) hasInfix;
@@ -57,21 +59,16 @@ let
plainTunnel = generated.readDerivation services.proxy-suite-awg-plain.serviceConfig.ExecStart; plainTunnel = generated.readDerivation services.proxy-suite-awg-plain.serviceConfig.ExecStart;
dnsServer = dnsServerByTag (mkTProxyConfig singBox) "awg-dns-de"; dnsServer = dnsServerByTag (mkTProxyConfig singBox) "awg-dns-de";
warpInterface = evalProxySuite [ warpInterface = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; proxy.enable = true;
services.proxy-suite = { amneziaWg.enable = true;
enable = true; warp = {
proxy.enable = true; enable = true;
amneziaWg.enable = true; configFile = "/run/secrets/wgcf-profile.conf";
warp = { asOutbound = "interface";
enable = true; };
configFile = "/run/secrets/wgcf-profile.conf"; };
asOutbound = "interface";
};
};
}
];
in in
{ {
assertions = [ assertions = [
+28 -33
View File
@@ -1,25 +1,23 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkBadProxySuiteFixture, mkBadProxySuiteFixture,
mkFailingAssertions, mkFailingAssertions,
rejectsProxySuite,
mkProxyCtlDerived, mkProxyCtlDerived,
}: }:
let let
inherit (checkLib) mkProxySuite;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
defaultPackages = evalProxySuite [ defaultPackages = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; amneziaWg = {
services.proxy-suite = { enable = true;
enable = true; profiles.home.configFile = "/run/secrets/awg.conf";
amneziaWg = { };
enable = true; };
profiles.home.configFile = "/run/secrets/awg.conf";
};
};
}
];
awgOnly = evalProxySuite [ awgOnly = evalProxySuite [
{ {
system.stateVersion = "26.05"; system.stateVersion = "26.05";
@@ -108,21 +106,16 @@ let
fakeKernelModule = pkgs.runCommand "fake-amneziawg-module" { } '' fakeKernelModule = pkgs.runCommand "fake-amneziawg-module" { } ''
mkdir -p "$out/lib/modules" mkdir -p "$out/lib/modules"
''; '';
overrideFixture = evalProxySuite [ overrideFixture = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; amneziaWg = {
services.proxy-suite = { enable = true;
enable = true; toolsPackage = fakeTools;
amneziaWg = { userspacePackage = fakeUserspace;
enable = true; kernelModulePackage = fakeKernelModule;
toolsPackage = fakeTools; profiles.home.configFile = "/run/secrets/client.conf";
userspacePackage = fakeUserspace; };
kernelModulePackage = fakeKernelModule; };
profiles.home.configFile = "/run/secrets/client.conf";
};
};
}
];
withGlobalTun = evalProxySuite [ withGlobalTun = evalProxySuite [
{ {
@@ -340,7 +333,11 @@ in
}; };
}; };
} }
{ ]
# An AmneziaWG profile and a global proxy mode both autostarting. Message-matched: with
# `proxy.tun.autostart` (removed) this case used to fail on the option name instead.
++ [
(rejectsProxySuite "at most one AmneziaWG, TUN, or TProxy global mode may autostart" {
enable = true; enable = true;
proxy = { proxy = {
enable = true; enable = true;
@@ -351,10 +348,8 @@ in
url = "http://proxy.example.com:8080"; url = "http://proxy.example.com:8080";
} }
]; ];
tun = { tun.enable = true;
enable = true; autostart = "tun";
autostart = true;
};
}; };
amneziaWg = { amneziaWg = {
enable = true; enable = true;
@@ -364,6 +359,6 @@ in
configFile = "/run/home.conf"; configFile = "/run/home.conf";
}; };
}; };
} })
]; ];
} }
+2 -4
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -9,11 +10,8 @@
}: }:
let let
inherit (checkLib) startScript;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
startScript =
fixture:
generated.readDerivation
fixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart;
chained = evalProxySuite [ chained = evalProxySuite [
baseModule baseModule
+4
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -12,6 +13,7 @@
let let
fixtures = import ./core-proxy/fixtures.nix { fixtures = import ./core-proxy/fixtures.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -40,6 +42,7 @@ let
; ;
routingDnsChecks = import ./core-proxy/routing-dns.nix { routingDnsChecks = import ./core-proxy/routing-dns.nix {
inherit checkLib;
inherit inherit
hasRuleSet hasRuleSet
dnsHasRuleSet dnsHasRuleSet
@@ -57,6 +60,7 @@ let
; ;
}; };
serviceDefaultChecks = import ./core-proxy/service-defaults.nix { serviceDefaultChecks = import ./core-proxy/service-defaults.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
minimal minimal
+4 -6
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -8,6 +9,7 @@
}: }:
let let
inherit (checkLib) startScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
customSingBoxPackage = pkgs.writeShellScriptBin "sing-box" '' customSingBoxPackage = pkgs.writeShellScriptBin "sing-box" ''
@@ -20,9 +22,7 @@ let
} }
]; ];
customSingBoxPackageBin = "${builtins.unsafeDiscardStringContext (toString customSingBoxPackage)}/bin/sing-box"; customSingBoxPackageBin = "${builtins.unsafeDiscardStringContext (toString customSingBoxPackage)}/bin/sing-box";
customSingBoxPackageStartScript = generated.readDerivation ( customSingBoxPackageStartScript = startScript customSingBoxPackageFixture;
customSingBoxPackageFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
routingOrFixture = evalProxySuite [ routingOrFixture = evalProxySuite [
{ {
@@ -125,9 +125,7 @@ let
}; };
} }
]; ];
urlTestCustomStartScript = generated.readDerivation ( urlTestCustomStartScript = startScript urlTestCustomFixture;
urlTestCustomFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
noProxyBackendDefaultFixture = evalProxySuite [ noProxyBackendDefaultFixture = evalProxySuite [
{ {
+17 -52
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
hasRuleSet, hasRuleSet,
dnsHasRuleSet, dnsHasRuleSet,
dnsServerByTag, dnsServerByTag,
@@ -14,25 +15,16 @@
routingOrGeoIPRules, routingOrGeoIPRules,
}: }:
let
inherit (checkLib) ok;
in
{ {
assertions = [ assertions = [
# -- routing rule entries with domains and geoips preserve both matchers, and the named outbound -- # -- routing rule entries with domains and geoips preserve both matchers, and the named outbound --
( (ok (builtins.length routingOrDomainRules == 1))
assert builtins.length routingOrDomainRules == 1; (ok (builtins.length routingOrGeoIPRules == 1))
true (ok ((builtins.head routingOrDomainRules).outbound == "primary"))
) (ok ((builtins.head routingOrGeoIPRules).outbound == "primary"))
(
assert builtins.length routingOrGeoIPRules == 1;
true
)
(
assert (builtins.head routingOrDomainRules).outbound == "primary";
true
)
(
assert (builtins.head routingOrGeoIPRules).outbound == "primary";
true
)
# -- default RU direct route and DNS rules are generated -- # -- default RU direct route and DNS rules are generated --
( (
@@ -50,34 +42,13 @@
assert remoteDns.detour == "proxy"; assert remoteDns.detour == "proxy";
true true
) )
( (ok (hasRuleSet ruDefaultRules "direct" "geosite-category-ru"))
assert hasRuleSet ruDefaultRules "direct" "geosite-category-ru"; (ok (hasRuleSet ruDefaultRules "direct" "geoip-ru"))
true (ok (dnsHasRuleSet ruDefaultConfig.dns.rules "geosite-category-ru"))
) (ok (!(hasRuleSet ruDisabledRules "direct" "geosite-category-ru")))
( (ok (!(hasRuleSet ruDisabledRules "direct" "geoip-ru")))
assert hasRuleSet ruDefaultRules "direct" "geoip-ru"; (ok (!(dnsHasRuleSet ruDisabledConfig.dns.rules "geosite-category-ru")))
true (ok (dnsHasRuleSet ruExplicitConfig.dns.rules "geosite-category-ru"))
)
(
assert dnsHasRuleSet ruDefaultConfig.dns.rules "geosite-category-ru";
true
)
(
assert !(hasRuleSet ruDisabledRules "direct" "geosite-category-ru");
true
)
(
assert !(hasRuleSet ruDisabledRules "direct" "geoip-ru");
true
)
(
assert !(dnsHasRuleSet ruDisabledConfig.dns.rules "geosite-category-ru");
true
)
(
assert dnsHasRuleSet ruExplicitConfig.dns.rules "geosite-category-ru";
true
)
# -- DNS overrides map to sing-box server entries -- # -- DNS overrides map to sing-box server entries --
( (
@@ -102,13 +73,7 @@
) )
# -- block route geosite and geoip sets are emitted -- # -- block route geosite and geoip sets are emitted --
( (ok (hasRuleSet blockGeoRules "block" "geosite-category-ads-all"))
assert hasRuleSet blockGeoRules "block" "geosite-category-ads-all"; (ok (hasRuleSet blockGeoRules "block" "geoip-cn"))
true
)
(
assert hasRuleSet blockGeoRules "block" "geoip-cn";
true
)
]; ];
} }
+8 -16
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
minimal, minimal,
customSingBoxPackageBin, customSingBoxPackageBin,
@@ -9,27 +10,18 @@
noProxyBackendDefaultFixture, noProxyBackendDefaultFixture,
}: }:
let
inherit (checkLib) ok;
in
{ {
assertions = [ assertions = [
# -- sing-box package override propagates into generated service scripts -- # -- sing-box package override propagates into generated service scripts --
( (ok (pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript))
assert pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript;
true
)
# -- proxy defaults and urltest settings are applied -- # -- proxy defaults and urltest settings are applied --
( (ok (proxyDirectConfig.dns.final == "local"))
assert proxyDirectConfig.dns.final == "local"; (ok (ruDefaultConfig.dns.final == "remote"))
true (ok (ruDefaultConfig.route.default_domain_resolver == "local"))
)
(
assert ruDefaultConfig.dns.final == "remote";
true
)
(
assert ruDefaultConfig.route.default_domain_resolver == "local";
true
)
( (
assert builtins.match ".*telegram\\.org.*" urlTestCustomStartScript != null; assert builtins.match ".*telegram\\.org.*" urlTestCustomStartScript != null;
assert builtins.match ".*1m.*" urlTestCustomStartScript != null; assert builtins.match ".*1m.*" urlTestCustomStartScript != null;
+5 -12
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -12,6 +13,7 @@
}: }:
let let
inherit (checkLib) ok;
fixtures = import ./global-proxy-modes/fixtures.nix { fixtures = import ./global-proxy-modes/fixtures.nix {
inherit inherit
evalProxySuite evalProxySuite
@@ -49,10 +51,7 @@ let
in in
{ {
assertions = [ assertions = [
( (ok (tproxyWithFirewall.config.networking.firewall.enable))
assert tproxyWithFirewall.config.networking.firewall.enable;
true
)
( (
assert tproxyManualFixture.config.services.proxy-suite.proxy.autostart == null; assert tproxyManualFixture.config.services.proxy-suite.proxy.autostart == null;
assert tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".wantedBy == [ ]; assert tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".wantedBy == [ ];
@@ -140,10 +139,7 @@ in
assert tunDefaultConfig.route.auto_detect_interface == true; assert tunDefaultConfig.route.auto_detect_interface == true;
true true
) )
( (ok (tunManualFixture.config.networking.nftables.enable))
assert tunManualFixture.config.networking.nftables.enable;
true
)
( (
assert tunServiceConfig.ExecStartPre == tunServiceConfig.ExecStopPost; assert tunServiceConfig.ExecStartPre == tunServiceConfig.ExecStopPost;
assert pkgs.lib.hasInfix "delete table inet sing-box" tunCleanupScript; assert pkgs.lib.hasInfix "delete table inet sing-box" tunCleanupScript;
@@ -169,10 +165,7 @@ in
assert !(localDns ? detour); assert !(localDns ? detour);
true true
) )
( (ok (tunDefaultConfig.route.default_domain_resolver == "local"))
assert tunDefaultConfig.route.default_domain_resolver == "local";
true
)
( (
assert builtins.elem "network-online.target" assert builtins.elem "network-online.target"
tunManualFixture.config.systemd.services."proxy-suite-tun".after; tunManualFixture.config.systemd.services."proxy-suite-tun".after;
+2
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -9,6 +10,7 @@
let let
fixtures = import ./hybrid-backend/fixtures.nix { fixtures = import ./hybrid-backend/fixtures.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
+8 -18
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -7,6 +8,7 @@
}: }:
let let
inherit (checkLib) startScript unitScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
hybridModule = { hybridModule = {
@@ -36,15 +38,9 @@ let
hybridFixture = evalProxySuite [ hybridModule ]; hybridFixture = evalProxySuite [ hybridModule ];
hybridTproxyConfig = mkTProxyConfig hybridFixture; hybridTproxyConfig = mkTProxyConfig hybridFixture;
hybridTunConfig = mkTunConfig hybridFixture; hybridTunConfig = mkTunConfig hybridFixture;
hybridStartScript = generated.readDerivation ( hybridStartScript = startScript hybridFixture;
hybridFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart hybridTunStartScript = unitScript hybridFixture "proxy-suite-tun";
); hybridPerAppTunStartScript = unitScript hybridFixture "proxy-suite-per-app-tun";
hybridTunStartScript = generated.readDerivation (
hybridFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStart
);
hybridPerAppTunStartScript = generated.readDerivation (
hybridFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart
);
hybridBackendJqFilter = hybridBackendJqFilter =
import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
{ {
@@ -75,9 +71,7 @@ let
}; };
} }
]; ];
hybridXrayRawStartScript = generated.readDerivation ( hybridXrayRawStartScript = startScript hybridXrayRawFixture;
hybridXrayRawFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
hybridSubscriptionFixture = evalProxySuite [ hybridSubscriptionFixture = evalProxySuite [
{ {
@@ -98,12 +92,8 @@ let
}; };
} }
]; ];
hybridSubscriptionStartScript = generated.readDerivation ( hybridSubscriptionStartScript = startScript hybridSubscriptionFixture;
hybridSubscriptionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart hybridSubscriptionUpdateScript = unitScript hybridSubscriptionFixture "proxy-suite-subscription-update";
);
hybridSubscriptionUpdateScript = generated.readDerivation (
hybridSubscriptionFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
);
in in
{ {
inherit inherit
+79 -71
View File
@@ -17,85 +17,54 @@ let
}; };
forceEval = value: builtins.tryEval (builtins.deepSeq value true); forceEval = value: builtins.tryEval (builtins.deepSeq value true);
rg = "${pkgs.ripgrep}/bin/rg"; rg = "${pkgs.ripgrep}/bin/rg";
mkRouting = # The module's own wiring, so a check sees exactly what a running system generates.
mkAssembly =
fixture: fixture:
let import ../../modules/proxy-suite/assembly.nix {
cfg = fixture.config.services.proxy-suite;
in
import ../../modules/proxy-suite/rules.nix {
lib = pkgs.lib; lib = pkgs.lib;
inherit pkgs cfg zapret; inherit pkgs zapret;
cfg = fixture.config.services.proxy-suite;
packages = import ../../pkgs/default.nix { inherit pkgs; };
}; };
mkRouting = fixture: (mkAssembly fixture).rules;
mkRoutingRules = fixture: (mkRouting fixture).routingRules; mkRoutingRules = fixture: (mkRouting fixture).routingRules;
mkRouteModeRules = fixture: (mkRouting fixture).routeModeRules; mkRouteModeRules = fixture: (mkRouting fixture).routeModeRules;
mkProxyConfig = mkProxyConfig =
fixture: configAttr: fixture: configAttr:
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.fromJSON (
builtins.unsafeDiscardStringContext (generated.readDerivation configs.${configAttr}) builtins.unsafeDiscardStringContext (
generated.readDerivation (mkAssembly fixture).configs.${configAttr}
)
); );
mkTProxyConfig = fixture: mkProxyConfig fixture "tproxyFile"; mkTProxyConfig = fixture: mkProxyConfig fixture "tproxyFile";
mkTunConfig = fixture: mkProxyConfig fixture "tunFile"; mkTunConfig = fixture: mkProxyConfig fixture "tunFile";
mkPerAppTunConfig = fixture: mkProxyConfig fixture "perAppTunFile"; mkPerAppTunConfig = fixture: mkProxyConfig fixture "perAppTunFile";
mkInboundsConfig = fixture: mkProxyConfig fixture "proxyInboundsFile"; mkInboundsConfig = fixture: mkProxyConfig fixture "proxyInboundsFile";
mkInboundsSpec = fixture: mkProxyConfig fixture "proxyInboundsSpecFile"; mkInboundsSpec = fixture: mkProxyConfig fixture "proxyInboundsSpecFile";
mkTProxyNftRules = mkNftRules = fixture: attr: generated.readDerivation (mkAssembly fixture).nftr.${attr};
fixture: mkTProxyNftRules = fixture: mkNftRules fixture "nftablesRulesFile";
let mkPerAppZapretNftRules = fixture: mkNftRules fixture "perAppZapretRulesFile";
cfg = fixture.config.services.proxy-suite; mkPerAppUserRules = fixture: (mkAssembly fixture).context.perAppRouting;
nftr = import ../../modules/proxy-suite/nftables.nix { # One assertion as a list element: `ok (x == y)` where the check lists want a true.
lib = pkgs.lib; ok =
inherit pkgs cfg; condition:
}; assert condition;
in true;
generated.readDerivation nftr.nftablesRulesFile; # A fixture from nothing but proxy-suite settings, the shape most checks want.
mkPerAppZapretNftRules = mkProxySuite =
fixture: proxySuiteConfig:
let evalProxySuite [
cfg = fixture.config.services.proxy-suite; {
nftr = import ../../modules/proxy-suite/nftables.nix { system.stateVersion = "26.05";
lib = pkgs.lib; services.proxy-suite = proxySuiteConfig;
inherit pkgs cfg; }
}; ];
in # The text of the program a unit starts, without import-from-derivation.
generated.readDerivation nftr.perAppZapretRulesFile; unitScript =
mkPerAppUserRules = fixture: unit:
fixture: generated.readDerivation fixture.config.systemd.services.${unit}.serviceConfig.ExecStart;
let # The local proxy's start script, which most checks read their expectations out of.
cfg = fixture.config.services.proxy-suite; startScript = fixture: unitScript fixture "proxy-suite-socks";
derived = import ../../modules/proxy-suite/derived.nix {
lib = pkgs.lib;
inherit cfg;
};
nftr = import ../../modules/proxy-suite/nftables.nix {
lib = pkgs.lib;
inherit pkgs cfg;
};
in
import ../../modules/proxy-suite/service/per-app-routing/user-rules.nix {
lib = pkgs.lib;
inherit pkgs;
inherit (derived)
perAppRoutingTun
perAppRoutingTproxy
perAppZapretCfg
;
perAppTunSliceName = "proxy-suite-per-app-tun.slice";
perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice";
perAppZapretSliceName = "proxy-suite-per-app-zapret.slice";
inherit (nftr) nft;
awk = "${pkgs.gawk}/bin/awk";
grepBin = "${pkgs.gnugrep}/bin/grep";
findBin = "${pkgs.findutils}/bin/find";
headBin = "${pkgs.coreutils}/bin/head";
};
hasDirectDomain = hasDirectDomain =
rules: domain: rules: domain:
builtins.any ( builtins.any (
@@ -143,11 +112,6 @@ let
builtins.head ( builtins.head (
builtins.filter (line: pkgs.lib.hasPrefix prefix line) (pkgs.lib.splitString "\n" text) builtins.filter (line: pkgs.lib.hasPrefix prefix line) (pkgs.lib.splitString "\n" text)
); );
lineContaining =
text: infix:
builtins.head (
builtins.filter (line: pkgs.lib.hasInfix infix line) (pkgs.lib.splitString "\n" text)
);
shellValueByPrefix = shellValueByPrefix =
text: prefix: text: prefix:
let let
@@ -210,6 +174,42 @@ let
assert (evaluate case).success == false; assert (evaluate case).success == false;
true true
) cases; ) cases;
# The messages of the assertions a config fails. Only the failing ones are forced, so an
# unrelated module's lazily-broken message (nixpkgs has some) never gets in the way. A
# fixture that does not evaluate at all reports that instead, so it cannot pass silently.
failedAssertions =
modules:
let
messages = map (a: a.message) (
builtins.filter (a: !a.assertion) (evalProxySuite modules).config.assertions
);
forced = builtins.tryEval (builtins.deepSeq messages messages);
in
if forced.success then forced.value else [ "the fixture does not evaluate" ];
# A bad config must fail *for the stated reason*: without the message, a case that stops
# evaluating for an unrelated reason (a renamed option, say) passes while testing nothing.
# Forcing the assertions rather than a whole system toplevel is also ~30x cheaper.
rejectsRaw =
expected: modules:
let
messages = failedAssertions modules;
in
if builtins.any (message: pkgs.lib.hasInfix expected message) messages then
true
else
throw (
"proxy-suite checks: expected a failure mentioning ${builtins.toJSON expected}, got: "
+ builtins.concatStringsSep " | " messages
);
rejects = expected: modules: rejectsRaw expected ([ baseModule ] ++ modules);
rejectsProxySuite =
expected: proxySuiteConfig:
rejectsRaw expected [
{
system.stateVersion = "26.05";
services.proxy-suite = proxySuiteConfig;
}
];
mkProxyCtlDerived = mkProxyCtlDerived =
fixture: fixture:
let let
@@ -235,6 +235,7 @@ in
rg rg
evalProxySuite evalProxySuite
forceEval forceEval
mkAssembly
mkRouting mkRouting
mkRoutingRules mkRoutingRules
mkRouteModeRules mkRouteModeRules
@@ -246,6 +247,10 @@ in
mkTProxyNftRules mkTProxyNftRules
mkPerAppZapretNftRules mkPerAppZapretNftRules
mkPerAppUserRules mkPerAppUserRules
ok
mkProxySuite
unitScript
startScript
hasDirectDomain hasDirectDomain
hasDirectIP hasDirectIP
hasRuleSet hasRuleSet
@@ -256,13 +261,16 @@ in
packagePathMatches packagePathMatches
packageByPattern packageByPattern
lineByPrefix lineByPrefix
lineContaining
shellValueByPrefix shellValueByPrefix
baseModule baseModule
mkBadFixture mkBadFixture
mkBadFixtureRaw mkBadFixtureRaw
mkBadProxySuiteFixture mkBadProxySuiteFixture
mkFailingAssertions mkFailingAssertions
failedAssertions
rejects
rejectsRaw
rejectsProxySuite
mkProxyCtlDerived mkProxyCtlDerived
system system
nixpkgs nixpkgs
+4 -6
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -10,6 +11,7 @@
}: }:
let let
inherit (checkLib) startScript;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
localProxyAuthFixture = evalProxySuite [ localProxyAuthFixture = evalProxySuite [
@@ -21,9 +23,7 @@ let
}; };
} }
]; ];
localProxyAuthStartScript = generated.readDerivation ( localProxyAuthStartScript = startScript localProxyAuthFixture;
localProxyAuthFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
localProxyAuthBackendJqFilter = localProxyAuthBackendJqFilter =
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
{ {
@@ -57,9 +57,7 @@ let
_localProxyAuthPasswordFile = mkProxyCtlDerived localProxyAuthPasswordFileFixture; _localProxyAuthPasswordFile = mkProxyCtlDerived localProxyAuthPasswordFileFixture;
localProxyAuthPasswordFileWrapper = _localProxyAuthPasswordFile.wrapper; localProxyAuthPasswordFileWrapper = _localProxyAuthPasswordFile.wrapper;
localProxyAuthPasswordFileScript = _localProxyAuthPasswordFile.script; localProxyAuthPasswordFileScript = _localProxyAuthPasswordFile.script;
localProxyAuthPasswordFileStartScript = generated.readDerivation ( localProxyAuthPasswordFileStartScript = startScript localProxyAuthPasswordFileFixture;
localProxyAuthPasswordFileFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
invalidLocalProxyAuthAssertions = mkFailingAssertions mkBadFixture [ invalidLocalProxyAuthAssertions = mkFailingAssertions mkBadFixture [
# Auth requires both username and a password source. # Auth requires both username and a password source.
+23 -6
View File
@@ -5,6 +5,7 @@
let let
inherit (checkLib) inherit (checkLib)
ok
mkRouting mkRouting
evalProxySuite evalProxySuite
mkRoutingRules mkRoutingRules
@@ -25,13 +26,14 @@ let
mkZapretBaseFor mkZapretBaseFor
mkZapretBase mkZapretBase
packagePathMatches packagePathMatches
packageByPattern
shellValueByPrefix shellValueByPrefix
baseModule baseModule
mkBadFixture mkBadFixture
mkBadFixtureRaw mkBadFixtureRaw
mkBadProxySuiteFixture mkBadProxySuiteFixture
mkFailingAssertions mkFailingAssertions
rejects
rejectsProxySuite
mkProxyCtlDerived mkProxyCtlDerived
; ;
@@ -47,6 +49,7 @@ let
minimalSocksService = minimal.config.systemd.services."proxy-suite-socks"; minimalSocksService = minimal.config.systemd.services."proxy-suite-socks";
coreProxyChecks = import ./core-proxy.nix { coreProxyChecks = import ./core-proxy.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -62,6 +65,7 @@ let
inherit (coreProxyChecks) ruDefaultConfig; inherit (coreProxyChecks) ruDefaultConfig;
routeModeChecks = import ./route-mode.nix { routeModeChecks = import ./route-mode.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -74,6 +78,7 @@ let
}; };
subscriptionChecks = import ./subscriptions.nix { subscriptionChecks = import ./subscriptions.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -93,6 +98,7 @@ let
}; };
localProxyAuthChecks = import ./local-proxy-auth.nix { localProxyAuthChecks = import ./local-proxy-auth.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -106,6 +112,7 @@ let
}; };
sshProxyChecks = import ./ssh-proxy.nix { sshProxyChecks = import ./ssh-proxy.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -117,6 +124,7 @@ let
}; };
warpChecks = import ./warp.nix { warpChecks = import ./warp.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -126,6 +134,7 @@ let
}; };
torChecks = import ./tor.nix { torChecks = import ./tor.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -141,6 +150,7 @@ let
}; };
proxyInboundsChecks = import ./proxy-inbounds.nix { proxyInboundsChecks = import ./proxy-inbounds.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -151,6 +161,7 @@ let
}; };
perAppRoutingChecks = import ./per-app-routing.nix { perAppRoutingChecks = import ./per-app-routing.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -164,6 +175,7 @@ let
mkZapretBaseFor mkZapretBaseFor
mkBadFixture mkBadFixture
mkFailingAssertions mkFailingAssertions
rejects
minimalProxyCtlScript minimalProxyCtlScript
; ;
}; };
@@ -172,6 +184,7 @@ let
inherit mkBadProxySuiteFixture mkFailingAssertions; inherit mkBadProxySuiteFixture mkFailingAssertions;
}; };
chainingDnsChecks = import ./chaining-dns.nix { chainingDnsChecks = import ./chaining-dns.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -184,7 +197,9 @@ let
}; };
amneziaWgChecks = import ./amnezia-wg.nix { amneziaWgChecks = import ./amnezia-wg.nix {
inherit checkLib;
inherit inherit
rejectsProxySuite
pkgs pkgs
evalProxySuite evalProxySuite
mkBadProxySuiteFixture mkBadProxySuiteFixture
@@ -194,6 +209,7 @@ let
}; };
amneziaWgOutboundChecks = import ./amnezia-wg-outbound.nix { amneziaWgOutboundChecks = import ./amnezia-wg-outbound.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -206,6 +222,7 @@ let
}; };
globalProxyModeChecks = import ./global-proxy-modes.nix { globalProxyModeChecks = import ./global-proxy-modes.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -221,6 +238,7 @@ let
}; };
zapretChecks = import ./zapret.nix { zapretChecks = import ./zapret.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -246,6 +264,7 @@ let
}; };
tgWsProxyChecks = import ./tg-ws-proxy.nix { tgWsProxyChecks = import ./tg-ws-proxy.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -262,11 +281,12 @@ let
}; };
serverModuleChecks = import ./server-module.nix { serverModuleChecks = import ./server-module.nix {
inherit pkgs mkInboundsSpec; inherit checkLib pkgs mkInboundsSpec;
inherit (checkLib) system nixpkgs proxySuiteModule; inherit (checkLib) system nixpkgs proxySuiteModule;
}; };
xrayBackendChecks = import ./xray-backends.nix { xrayBackendChecks = import ./xray-backends.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -283,10 +303,7 @@ let
validated = builtins.all (x: x) ( validated = builtins.all (x: x) (
[ [
( (ok (minimal.config.services.proxy-suite.proxy.listener.address == "127.0.0.1"))
assert minimal.config.services.proxy-suite.proxy.listener.address == "127.0.0.1";
true
)
] ]
++ coreProxyChecks.assertions ++ coreProxyChecks.assertions
++ localProxyAuthChecks.assertions ++ localProxyAuthChecks.assertions
-57
View File
@@ -1,57 +0,0 @@
{ pkgs }:
{
build-outbound-parser =
pkgs.runCommand "build-outbound-parser-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-build-outbound.py}
touch "$out"
'';
build-inbound-renderer =
pkgs.runCommand "build-inbound-renderer-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-build-inbound.py}
touch "$out"
'';
fetch-subscription-parser =
pkgs.runCommand "fetch-subscription-parser-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-fetch-subscription.py}
touch "$out"
'';
warp-outbound-parser =
pkgs.runCommand "warp-outbound-parser-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-warp-outbound.py}
touch "$out"
'';
amneziawg-config-parser =
pkgs.runCommand "amneziawg-config-parser-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-amneziawg-config.py}
touch "$out"
'';
awg-inbound-state =
pkgs.runCommand "awg-inbound-state-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1
export PYTHONPATH=${../../scripts}:$PYTHONPATH
python ${../../scripts/test-awg-inbound.py}
touch "$out"
'';
}
+7 -20
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -7,6 +8,7 @@
}: }:
let let
inherit (checkLib) ok;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
perAppRoutingProxychainsFixture = evalProxySuite [ perAppRoutingProxychainsFixture = evalProxySuite [
@@ -67,20 +69,14 @@ in
{ {
assertions = [ assertions = [
# -- perAppRouting: proxychains/direct profile config is accepted -- # -- perAppRouting: proxychains/direct profile config is accepted --
( (ok (perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.enable))
assert perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.enable;
true
)
( (
assert assert
builtins.length perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.profiles builtins.length perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.profiles
== 2; == 2;
true true
) )
( (ok (builtins.length perAppRoutingProxychainsProfiles == 2))
assert builtins.length perAppRoutingProxychainsProfiles == 2;
true
)
# -- perAppRouting: createDefaultProfiles injects curated proxychains profile -- # -- perAppRouting: createDefaultProfiles injects curated proxychains profile --
( (
@@ -91,10 +87,7 @@ in
) )
# -- perAppRouting: createDefaultProfiles = false injects no curated profiles -- # -- perAppRouting: createDefaultProfiles = false injects no curated profiles --
( (ok (builtins.length perAppRoutingNoDefaultProfiles == 0))
assert builtins.length perAppRoutingNoDefaultProfiles == 0;
true
)
# -- perAppRouting: proxy-ctl script embeds wrap/apps commands -- # -- perAppRouting: proxy-ctl script embeds wrap/apps commands --
( (
@@ -115,15 +108,9 @@ in
) )
# -- proxy-ctl: restart skips services that are not present in zapret-only or tg-only builds -- # -- proxy-ctl: restart skips services that are not present in zapret-only or tg-only builds --
( (ok (pkgs.lib.hasInfix "proxy-suite-tg-ws-proxy" minimalProxyCtlScript))
assert pkgs.lib.hasInfix "proxy-suite-tg-ws-proxy" minimalProxyCtlScript;
true
)
# -- perAppRouting: generated proxy-ctl script dispatches through proxychains4 -- # -- perAppRouting: generated proxy-ctl script dispatches through proxychains4 --
( (ok (pkgs.lib.hasInfix "export PROXYCHAINS_QUIET_ARG=-q" perAppRoutingProxychainsScript))
assert pkgs.lib.hasInfix "export PROXYCHAINS_QUIET_ARG=-q" perAppRoutingProxychainsScript;
true
)
]; ];
} }
+3 -4
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -7,6 +8,7 @@
}: }:
let let
inherit (checkLib) ok;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
perAppRoutingTproxyFixture = evalProxySuite [ perAppRoutingTproxyFixture = evalProxySuite [
@@ -51,10 +53,7 @@ in
) )
# -- perAppRouting: generated proxy-ctl script dispatches tproxy profiles through systemd slices -- # -- perAppRouting: generated proxy-ctl script dispatches tproxy profiles through systemd slices --
( (ok (pkgs.lib.hasInfix "PER_APP_ROUTING_TPROXY_ENABLED" perAppRoutingTproxyScript))
assert pkgs.lib.hasInfix "PER_APP_ROUTING_TPROXY_ENABLED" perAppRoutingTproxyScript;
true
)
# -- perAppRouting: app TProxy service and helper units are created -- # -- perAppRouting: app TProxy service and helper units are created --
( (
+9 -17
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -9,6 +10,7 @@
}: }:
let let
inherit (checkLib) ok;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
perAppRoutingTunFixture = evalProxySuite [ perAppRoutingTunFixture = evalProxySuite [
@@ -79,10 +81,7 @@ in
) )
# -- perAppRouting: generated proxy-ctl script dispatches tun profiles through systemd slices -- # -- perAppRouting: generated proxy-ctl script dispatches tun profiles through systemd slices --
( (ok (pkgs.lib.hasInfix "PER_APP_ROUTING_TUN_ENABLED" perAppRoutingTunScript))
assert pkgs.lib.hasInfix "PER_APP_ROUTING_TUN_ENABLED" perAppRoutingTunScript;
true
)
# -- perAppRouting: user mark script installs fwmark + conntrack mark rules -- # -- perAppRouting: user mark script installs fwmark + conntrack mark rules --
( (
@@ -122,10 +121,7 @@ in
) )
# -- perAppRouting: app TUN uses local domain resolver and avoids global auto-routing -- # -- perAppRouting: app TUN uses local domain resolver and avoids global auto-routing --
( (ok (perAppRoutingTunConfig.route.default_domain_resolver == "local"))
assert perAppRoutingTunConfig.route.default_domain_resolver == "local";
true
)
# -- perAppRouting: app TUN does not set outbound routing marks when TProxy is disabled -- # -- perAppRouting: app TUN does not set outbound routing marks when TProxy is disabled --
( (
@@ -165,12 +161,11 @@ in
# -- perAppRouting: wrapped apps' replies to incoming connections skip the mark (and the # -- perAppRouting: wrapped apps' replies to incoming connections skip the mark (and the
# user rule appended after it), so they leave directly -- # user rule appended after it), so they leave directly --
( (ok (
assert pkgs.lib.hasInfix "ct direction reply return" ( pkgs.lib.hasInfix "ct direction reply return" (
builtins.head (pkgs.lib.splitString "ct mark 16 meta mark set 16" perAppRoutingTunNftRules) builtins.head (pkgs.lib.splitString "ct mark 16 meta mark set 16" perAppRoutingTunNftRules)
); )
true ))
)
# -- perAppRouting: wrapped apps' DNS reaches the app TUN even when the resolver sits on # -- perAppRouting: wrapped apps' DNS reaches the app TUN even when the resolver sits on
# a local or reserved address, and their local IPv6 still leaves directly -- # a local or reserved address, and their local IPv6 still leaves directly --
@@ -191,9 +186,6 @@ in
) )
# -- perAppRouting: app TUN enables nftables -- # -- perAppRouting: app TUN enables nftables --
( (ok (perAppRoutingTunFixture.config.networking.nftables.enable))
assert perAppRoutingTunFixture.config.networking.nftables.enable;
true
)
]; ];
} }
@@ -1,102 +1,102 @@
{ # Marks and route tables per-app routing must not share with the global backends. Each case
mkBadFixture, # names the assertion it expects, so a case that stops evaluating for another reason fails.
mkFailingAssertions, { rejects }:
}:
{ {
assertions = mkFailingAssertions mkBadFixture [ assertions = [
# app TUN fwmark must not collide with global TProxy proxyMark. (rejects "perAppRouting.tun.fwmark must differ from proxy.tproxy.proxyMark" [
[
{
services.proxy-suite = {
proxy.tproxy.proxyMark = 7;
proxy.tun.perApp = {
enable = true;
fwmark = 7;
};
perAppRouting.enable = true;
};
}
]
# app TProxy fwmark must not collide with global TProxy proxyMark.
[
{ {
services.proxy-suite = { services.proxy-suite = {
proxy.tproxy = { proxy.tproxy = {
enable = true;
proxyMark = 7;
};
perAppRouting = {
enable = true;
tun = {
enable = true;
fwmark = 7;
};
};
};
}
])
(rejects "perAppRouting.tproxy.fwmark must differ from proxy.tproxy.proxyMark" [
{
services.proxy-suite = {
proxy.tproxy = {
enable = true;
proxyMark = 8; proxyMark = 8;
perApp = { };
perAppRouting = {
enable = true;
tproxy = {
enable = true; enable = true;
fwmark = 8; fwmark = 8;
}; };
}; };
perAppRouting.enable = true;
}; };
} }
] ])
(rejects "perAppRouting.tun.fwmark and perAppRouting.tproxy.fwmark must differ" [
# app TUN and TProxy backends must use distinct marks and route tables.
[
{ {
services.proxy-suite = { services.proxy-suite.perAppRouting = {
proxy.tun.perApp = { enable = true;
tun = {
enable = true; enable = true;
fwmark = 11; fwmark = 11;
}; };
proxy.tproxy.perApp = { tproxy = {
enable = true; enable = true;
fwmark = 11; fwmark = 11;
}; };
perAppRouting.enable = true;
}; };
} }
] ])
[ (rejects "perAppRouting.tun.routeTable and perAppRouting.tproxy.routeTable must differ" [
{ {
services.proxy-suite = { services.proxy-suite.perAppRouting = {
proxy.tun.perApp = { enable = true;
tun = {
enable = true; enable = true;
routeTable = 100; routeTable = 100;
}; };
proxy.tproxy.perApp = { tproxy = {
enable = true; enable = true;
routeTable = 100; routeTable = 100;
}; };
perAppRouting.enable = true;
}; };
} }
] ])
(rejects "perAppRouting.tun.fwmark and perAppRouting.zapret.filterMark must differ" [
# per-app zapret marks must not collide with TUN/TProxy marks.
[
{ {
services.proxy-suite = { services.proxy-suite.perAppRouting = {
proxy.tun.perApp = { enable = true;
tun = {
enable = true; enable = true;
fwmark = 12; fwmark = 12;
}; };
zapret.perApp = { zapret = {
enable = true; enable = true;
filterMark = 12; filterMark = 12;
}; };
perAppRouting.enable = true;
}; };
} }
] ])
[ (rejects "perAppRouting.tproxy.fwmark and perAppRouting.zapret.filterMark must differ" [
{ {
services.proxy-suite = { services.proxy-suite.perAppRouting = {
proxy.tproxy.perApp = { enable = true;
tproxy = {
enable = true; enable = true;
fwmark = 13; fwmark = 13;
}; };
zapret.perApp = { zapret = {
enable = true; enable = true;
filterMark = 13; filterMark = 13;
}; };
perAppRouting.enable = true;
}; };
} }
] ])
]; ];
} }
+3 -3
View File
@@ -1,15 +1,15 @@
{ {
checkLib,
mkBadFixture, mkBadFixture,
mkFailingAssertions, mkFailingAssertions,
rejects,
}: }:
let let
profileChecks = import ./per-app-routing-validation-profiles.nix { profileChecks = import ./per-app-routing-validation-profiles.nix {
inherit mkBadFixture mkFailingAssertions; inherit mkBadFixture mkFailingAssertions;
}; };
resourceChecks = import ./per-app-routing-validation-resources.nix { resourceChecks = import ./per-app-routing-validation-resources.nix { inherit rejects; };
inherit mkBadFixture mkFailingAssertions;
};
in in
{ {
assertions = profileChecks.assertions ++ resourceChecks.assertions; assertions = profileChecks.assertions ++ resourceChecks.assertions;
+4 -8
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -10,6 +11,7 @@
}: }:
let let
inherit (checkLib) ok;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
perAppRoutingZapretFixture = evalProxySuite [ perAppRoutingZapretFixture = evalProxySuite [
@@ -168,10 +170,7 @@ in
) )
# -- perAppRouting: generated proxy-ctl script dispatches zapret profiles through systemd slices -- # -- perAppRouting: generated proxy-ctl script dispatches zapret profiles through systemd slices --
( (ok (pkgs.lib.hasInfix "PER_APP_ROUTING_ZAPRET_ENABLED" perAppRoutingZapretScript))
assert pkgs.lib.hasInfix "PER_APP_ROUTING_ZAPRET_ENABLED" perAppRoutingZapretScript;
true
)
# -- perAppRouting: app zapret service and helper units are created -- # -- perAppRouting: app zapret service and helper units are created --
( (
@@ -213,10 +212,7 @@ in
) )
# -- perAppRouting: app zapret startup installs nftables backend -- # -- perAppRouting: app zapret startup installs nftables backend --
( (ok (pkgs.lib.hasInfix "proxy_suite_per_app_zapret_mark" perAppRoutingZapretStartScript))
assert pkgs.lib.hasInfix "proxy_suite_per_app_zapret_mark" perAppRoutingZapretStartScript;
true
)
]; ];
+9 -1
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -11,11 +12,13 @@
mkZapretBaseFor, mkZapretBaseFor,
mkBadFixture, mkBadFixture,
mkFailingAssertions, mkFailingAssertions,
rejects,
minimalProxyCtlScript, minimalProxyCtlScript,
}: }:
let let
tunChecks = import ./per-app-routing-tun.nix { tunChecks = import ./per-app-routing-tun.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -27,6 +30,7 @@ let
; ;
}; };
tproxyChecks = import ./per-app-routing-tproxy.nix { tproxyChecks = import ./per-app-routing-tproxy.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -36,6 +40,7 @@ let
; ;
}; };
zapretChecks = import ./per-app-routing-zapret.nix { zapretChecks = import ./per-app-routing-zapret.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -48,9 +53,11 @@ let
; ;
}; };
validationChecks = import ./per-app-routing-validation.nix { validationChecks = import ./per-app-routing-validation.nix {
inherit mkBadFixture mkFailingAssertions; inherit checkLib;
inherit mkBadFixture mkFailingAssertions rejects;
}; };
userControlChecks = import ./user-control.nix { userControlChecks = import ./user-control.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -58,6 +65,7 @@ let
; ;
}; };
proxychainsChecks = import ./per-app-routing-proxychains.nix { proxychainsChecks = import ./per-app-routing-proxychains.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
+63 -237
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -7,6 +8,7 @@
}: }:
let let
inherit (checkLib) ok;
inherit (pkgs) lib; inherit (pkgs) lib;
realityListener = { realityListener = {
@@ -515,29 +517,14 @@ let
assertions = [ assertions = [
# Listeners are rendered at start time. # Listeners are rendered at start time.
( (ok (relayConfig.inbounds == [ ]))
assert relayConfig.inbounds == [ ];
true
)
# AsIs when relayed through sing-box; IPOnDemand when XRay dials (see the template). # AsIs when relayed through sing-box; IPOnDemand when XRay dials (see the template).
( (ok (relayConfig.routing.domainStrategy == "AsIs"))
assert relayConfig.routing.domainStrategy == "AsIs"; (ok (exitConfig.routing.domainStrategy == "IPOnDemand"))
true
)
(
assert exitConfig.routing.domainStrategy == "IPOnDemand";
true
)
( (ok (hasOutbound relayConfig "proxy"))
assert hasOutbound relayConfig "proxy"; (ok ((ruleByTag relayConfig "inbound-final").outboundTag == "proxy"))
true
)
(
assert (ruleByTag relayConfig "inbound-final").outboundTag == "proxy";
true
)
( (
assert assert
(builtins.head (builtins.filter (ob: ob.tag == "proxy") relayConfig.outbounds)).protocol == "socks"; (builtins.head (builtins.filter (ob: ob.tag == "proxy") relayConfig.outbounds)).protocol == "socks";
@@ -556,36 +543,15 @@ let
) )
# A pure exit node needs no proxy outbound at all. # A pure exit node needs no proxy outbound at all.
( (ok (!hasOutbound exitConfig "proxy"))
assert !hasOutbound exitConfig "proxy"; (ok ((ruleByTag exitConfig "inbound-final").outboundTag == "direct"))
true
)
(
assert (ruleByTag exitConfig "inbound-final").outboundTag == "direct";
true
)
# Safety rules come first. # Safety rules come first.
( (ok (builtins.head (ruleTags relayConfig) == "inbound-block-private"))
assert builtins.head (ruleTags relayConfig) == "inbound-block-private"; (ok ((ruleByTag relayConfig "inbound-block-private").outboundTag == "block"))
true (ok ((ruleByTag relayConfig "inbound-block-ru-domain").domain == [ "geosite:category-ru" ]))
) (ok ((ruleByTag relayConfig "inbound-block-ru-ip").ip == [ "geoip:ru" ]))
( (ok (!builtins.elem "inbound-block-private" (ruleTags unguardedConfig)))
assert (ruleByTag relayConfig "inbound-block-private").outboundTag == "block";
true
)
(
assert (ruleByTag relayConfig "inbound-block-ru-domain").domain == [ "geosite:category-ru" ];
true
)
(
assert (ruleByTag relayConfig "inbound-block-ru-ip").ip == [ "geoip:ru" ];
true
)
(
assert !builtins.elem "inbound-block-private" (ruleTags unguardedConfig);
true
)
# serverAddress is exempt after blockPrivate, before the country blocks. # serverAddress is exempt after blockPrivate, before the country blocks.
( (
assert assert
@@ -596,10 +562,7 @@ let
]; ];
true true
) )
( (ok ((ruleByTag namedConfig "inbound-server-address-direct").domain == [ "full:vpn.example.ru" ]))
assert (ruleByTag namedConfig "inbound-server-address-direct").domain == [ "full:vpn.example.ru" ];
true
)
# Names that resolve private are refused where XRay dials them itself. # Names that resolve private are refused where XRay dials them itself.
( (
assert assert
@@ -612,64 +575,25 @@ let
true true
) )
# Only the listener ports, not every service on this host. # Only the listener ports, not every service on this host.
( (ok ((ruleByTag namedConfig "inbound-server-address-direct").port == "443"))
assert (ruleByTag namedConfig "inbound-server-address-direct").port == "443"; (ok ((ruleByTag blockedConfig "inbound-proxy-domain").inboundTag == [ "open" ]))
true (ok ((ruleByTag blockedConfig "inbound-server-address-direct").inboundTag == [ "open" ]))
)
(
assert (ruleByTag blockedConfig "inbound-proxy-domain").inboundTag == [ "open" ];
true
)
(
assert (ruleByTag blockedConfig "inbound-server-address-direct").inboundTag == [ "open" ];
true
)
# No address to exempt when it is detected at runtime instead. # No address to exempt when it is detected at runtime instead.
( (ok (!builtins.elem "inbound-server-address-direct" (ruleTags relayConfig)))
assert !builtins.elem "inbound-server-address-direct" (ruleTags relayConfig); (ok ((ruleByTag ipNamedConfig "inbound-server-address-direct").ip == [ "82.146.44.102" ]))
true (ok (!builtins.elem "inbound-block-ru-domain" (ruleTags unguardedConfig)))
)
(
assert (ruleByTag ipNamedConfig "inbound-server-address-direct").ip == [ "82.146.44.102" ];
true
)
(
assert !builtins.elem "inbound-block-ru-domain" (ruleTags unguardedConfig);
true
)
# A per-listener via becomes its own rule; listeners on the default do not. # A per-listener via becomes its own rule; listeners on the default do not.
( (ok (builtins.elem "inbound-via-local-exit" (ruleTags mixedConfig)))
assert builtins.elem "inbound-via-local-exit" (ruleTags mixedConfig); (ok (!builtins.elem "inbound-via-relayed" (ruleTags mixedConfig)))
true (ok ((ruleByTag mixedConfig "inbound-via-local-exit").inboundTag == [ "local-exit" ]))
) (ok ((ruleByTag mixedConfig "inbound-via-local-exit").outboundTag == "direct"))
(
assert !builtins.elem "inbound-via-relayed" (ruleTags mixedConfig);
true
)
(
assert (ruleByTag mixedConfig "inbound-via-local-exit").inboundTag == [ "local-exit" ];
true
)
(
assert (ruleByTag mixedConfig "inbound-via-local-exit").outboundTag == "direct";
true
)
# The pinned listener gets its own rule; the default one rides the final rule. # The pinned listener gets its own rule; the default one rides the final rule.
( (ok ((ruleByTag pinnedConfig "inbound-via-through-de").outboundTag == "de-vps"))
assert (ruleByTag pinnedConfig "inbound-via-through-de").outboundTag == "de-vps"; (ok ((ruleByTag pinnedConfig "inbound-final").outboundTag == "nl-vps"))
true
)
(
assert (ruleByTag pinnedConfig "inbound-final").outboundTag == "nl-vps";
true
)
# Pinned outbounds are injected at start and need no local proxy. # Pinned outbounds are injected at start and need no local proxy.
( (ok (!hasOutbound pinnedConfig "proxy"))
assert !hasOutbound pinnedConfig "proxy";
true
)
( (
assert assert
outboundTags pinnedConfig == [ outboundTags pinnedConfig == [
@@ -690,46 +614,19 @@ let
) )
# The final rule always comes last. # The final rule always comes last.
( (ok (lib.last (ruleTags relayConfig) == "inbound-final"))
assert lib.last (ruleTags relayConfig) == "inbound-final"; (ok (lib.last (ruleTags mixedConfig) == "inbound-final"))
true
)
(
assert lib.last (ruleTags mixedConfig) == "inbound-final";
true
)
# Without zapret running there is nothing to route around it. # Without zapret running there is nothing to route around it.
( (ok (!builtins.elem "inbound-zapret-direct-domain" (ruleTags relayConfig)))
assert !builtins.elem "inbound-zapret-direct-domain" (ruleTags relayConfig);
true
)
# The spec carries secret paths, never their contents. # The spec carries secret paths, never their contents.
( (ok (builtins.length relaySpec.listeners == 1))
assert builtins.length relaySpec.listeners == 1; (ok ((builtins.head relaySpec.listeners).tag == "vless-in"))
true (ok ((builtins.head relaySpec.listeners).listen == "::"))
) (ok ((builtins.head (builtins.head relaySpec.listeners).users).uuidFile == "/run/secrets/uuid"))
( (ok ((builtins.head relaySpec.listeners).reality.privateKeyFile == "/run/secrets/reality-key"))
assert (builtins.head relaySpec.listeners).tag == "vless-in"; (ok (relaySpec.shareLinks))
true
)
(
assert (builtins.head relaySpec.listeners).listen == "::";
true
)
(
assert (builtins.head (builtins.head relaySpec.listeners).users).uuidFile == "/run/secrets/uuid";
true
)
(
assert (builtins.head relaySpec.listeners).reality.privateKeyFile == "/run/secrets/reality-key";
true
)
(
assert relaySpec.shareLinks;
true
)
# Firewall: TCP for every listener, UDP only where the protocol uses it. # Firewall: TCP for every listener, UDP only where the protocol uses it.
( (
@@ -748,33 +645,15 @@ let
]; ];
true true
) )
( (ok (wsListener.port == 10002 && wsListener.sharePort == 443))
assert wsListener.port == 10002 && wsListener.sharePort == 443; (ok (noFirewallFixture.config.networking.firewall.allowedTCPPorts == [ ]))
true
)
(
assert noFirewallFixture.config.networking.firewall.allowedTCPPorts == [ ];
true
)
# The unit exists, and only waits on the client stack when it relays. # The unit exists, and only waits on the client stack when it relays.
( (ok ((service relayFixture).wantedBy == [ "multi-user.target" ]))
assert (service relayFixture).wantedBy == [ "multi-user.target" ]; (ok (builtins.elem "proxy-suite-socks.service" (service relayFixture).after))
true (ok (!builtins.elem "proxy-suite-socks.service" (service exitFixture).after))
)
(
assert builtins.elem "proxy-suite-socks.service" (service relayFixture).after;
true
)
(
assert !builtins.elem "proxy-suite-socks.service" (service exitFixture).after;
true
)
# Not `requires`: direct-routed listeners keep serving if the client is down. # Not `requires`: direct-routed listeners keep serving if the client is down.
( (ok ((service relayFixture).requires == [ ]))
assert (service relayFixture).requires == [ ];
true
)
# A stop collects what XRay counted since the last timer run. # A stop collects what XRay counted since the last timer run.
( (
assert assert
@@ -793,44 +672,20 @@ let
) )
# AmneziaWG: the spec carries each listener's loopback inbound, in listener order. # AmneziaWG: the spec carries each listener's loopback inbound, in listener order.
( (ok ((awgSpecListener "home").amneziaWg.internalPort == 18700))
assert (awgSpecListener "home").amneziaWg.internalPort == 18700; (ok ((awgSpecListener "roam").amneziaWg.internalPort == 18701))
true (ok ((awgSpecListener "home").amneziaWg.internalListen == "::"))
) (ok ((awgSpecListener "roam").amneziaWg.internalListen == "127.0.0.1"))
( (ok ((awgSpecListener "home").amneziaWg.fwmark == 2))
assert (awgSpecListener "roam").amneziaWg.internalPort == 18701; (ok ((awgSpecListener "home").amneziaWg.interfaceName == "awgi-home"))
true
)
(
assert (awgSpecListener "home").amneziaWg.internalListen == "::";
true
)
(
assert (awgSpecListener "roam").amneziaWg.internalListen == "127.0.0.1";
true
)
(
assert (awgSpecListener "home").amneziaWg.fwmark == 2;
true
)
(
assert (awgSpecListener "home").amneziaWg.interfaceName == "awgi-home";
true
)
( (
assert assert
(awgSpecListener "roam").amneziaWg.stateFile == "/var/lib/proxy-suite/awg-inbounds/roam/state.json"; (awgSpecListener "roam").amneziaWg.stateFile == "/var/lib/proxy-suite/awg-inbounds/roam/state.json";
true true
) )
( (ok (!((awgSpecListener "vless-in") ? amneziaWg)))
assert !((awgSpecListener "vless-in") ? amneziaWg);
true
)
# UDP only, and the interfaces past the host firewall. # UDP only, and the interfaces past the host firewall.
( (ok (awgFixture.config.networking.firewall.allowedTCPPorts == [ 443 ]))
assert awgFixture.config.networking.firewall.allowedTCPPorts == [ 443 ];
true
)
( (
assert assert
lib.sort lib.lessThan awgFixture.config.networking.firewall.allowedUDPPorts == [ lib.sort lib.lessThan awgFixture.config.networking.firewall.allowedUDPPorts == [
@@ -844,38 +699,21 @@ let
assert builtins.elem "awgi-roam" awgFixture.config.networking.firewall.trustedInterfaces; assert builtins.elem "awgi-roam" awgFixture.config.networking.firewall.trustedInterfaces;
true true
) )
( (ok (
assert lib.hasInfix ''iifname "awgi-home" accept'' lib.hasInfix ''iifname "awgi-home" accept'' awgFixture.config.networking.firewall.extraReversePathFilterRules
awgFixture.config.networking.firewall.extraReversePathFilterRules; ))
true
)
# The interfaces come up before XRay renders their links. # The interfaces come up before XRay renders their links.
( (ok (builtins.elem "proxy-suite-inbounds-awg.service" (service awgFixture).after))
assert builtins.elem "proxy-suite-inbounds-awg.service" (service awgFixture).after; (ok (builtins.elem "proxy-suite-inbounds-awg.service" (service awgFixture).wants))
true (ok (!(relayFixture.config.systemd.services ? "proxy-suite-inbounds-awg")))
)
(
assert builtins.elem "proxy-suite-inbounds-awg.service" (service awgFixture).wants;
true
)
(
assert !(relayFixture.config.systemd.services ? "proxy-suite-inbounds-awg");
true
)
( (
assert lib.hasInfix "rule add pref 8990 fwmark 20 table 103" (awgStartScript awgFixture); assert lib.hasInfix "rule add pref 8990 fwmark 20 table 103" (awgStartScript awgFixture);
assert lib.hasInfix "awg_inbound.py prepare" (awgStartScript awgFixture); assert lib.hasInfix "awg_inbound.py prepare" (awgStartScript awgFixture);
true true
) )
# IPv6 routing only where a listener has IPv6. # IPv6 routing only where a listener has IPv6.
( (ok (lib.hasInfix "-6 rule add pref 8990" (awgStartScript awgFixture)))
assert lib.hasInfix "-6 rule add pref 8990" (awgStartScript awgFixture); (ok (!lib.hasInfix "-6 rule add pref 8990" (awgStartScript awgProxyFixture)))
true
)
(
assert !lib.hasInfix "-6 rule add pref 8990" (awgStartScript awgProxyFixture);
true
)
# Transparent sockets only where there is something to divert. # Transparent sockets only where there is something to divert.
( (
assert lib.hasInfix "net_admin" (readInboundsStart awgFixture); assert lib.hasInfix "net_admin" (readInboundsStart awgFixture);
@@ -883,18 +721,9 @@ let
true true
) )
# Forwarding only for "lan" listeners. # Forwarding only for "lan" listeners.
( (ok (awgFixture.config.boot.kernel.sysctl."net.ipv4.ip_forward" == 1))
assert awgFixture.config.boot.kernel.sysctl."net.ipv4.ip_forward" == 1; (ok (awgFixture.config.boot.kernel.sysctl."net.ipv6.conf.all.forwarding" == 1))
true (ok (!(awgProxyFixture.config.services.proxy-suite.internal.sysctl ? "net.ipv4.ip_forward")))
)
(
assert awgFixture.config.boot.kernel.sysctl."net.ipv6.conf.all.forwarding" == 1;
true
)
(
assert !(awgProxyFixture.config.services.proxy-suite.internal.sysctl ? "net.ipv4.ip_forward");
true
)
# "lan" clients reach private networks and each other natively, "proxy" clients nothing but via. # "lan" clients reach private networks and each other natively, "proxy" clients nothing but via.
( (
let let
@@ -914,10 +743,7 @@ let
assert !lib.hasInfix "10.67.0.0/24 oifname" rules; assert !lib.hasInfix "10.67.0.0/24 oifname" rules;
true true
) )
( (ok (!lib.hasInfix "masquerade" (awgRules awgProxyFixture)))
assert !lib.hasInfix "masquerade" (awgRules awgProxyFixture);
true
)
] ]
++ failing; ++ failing;
+117
View File
@@ -0,0 +1,117 @@
# The Python unit tests, as Nix checks. Every entry is the same runCommand: the test file, the
# interpreter (with the packages it imports) and the env it needs.
{ pkgs }:
let
scripts = ../../scripts;
proxyCtl = ../../pkgs/proxy-ctl;
mkPythonCheck =
name:
{
file,
drv ? name,
python ? pkgs.python3,
env ? { },
extraInputs ? [ ],
buildInputs ? [ ],
}:
pkgs.runCommand "${drv}-check"
{
nativeBuildInputs = [ python ] ++ extraInputs;
inherit buildInputs;
}
''
export PYTHONDONTWRITEBYTECODE=1
${pkgs.lib.concatStringsSep "\n" (
pkgs.lib.mapAttrsToList (variable: value: "export ${variable}=${value}") env
)}
python ${file}
touch "$out"
'';
withPath = path: { PYTHONPATH = "${path}:$PYTHONPATH"; };
singBox = {
SING_BOX = "${pkgs.sing-box}/bin/sing-box";
};
in
pkgs.lib.mapAttrs mkPythonCheck {
# The runtime helpers the module's start scripts call: share-link parsing, inbound and
# AmneziaWG rendering, subscription fetching.
build-outbound-parser = {
file = "${scripts}/test-build-outbound.py";
env = withPath scripts;
};
build-inbound-renderer = {
file = "${scripts}/test-build-inbound.py";
env = withPath scripts;
};
fetch-subscription-parser = {
file = "${scripts}/test-fetch-subscription.py";
env = withPath scripts;
};
warp-outbound-parser = {
file = "${scripts}/test-warp-outbound.py";
env = withPath scripts;
};
amneziawg-config-parser = {
file = "${scripts}/test-amneziawg-config.py";
env = withPath scripts;
};
awg-inbound-state = {
file = "${scripts}/test-awg-inbound.py";
env = withPath scripts;
};
# The NFQWS_OPT rewrites the zapret v1 package build applies.
patch-zapret-config = {
file = "${scripts}/test-patch-zapret-config.py";
env = withPath scripts;
};
# proxy_ctl.py's function-level tests: the probe verdict table and exit walk,
# autoProxy learn/queue, inbound stats and subscriptions, apps run.
proxy-ctl-unit = {
drv = "proxy-suite-proxy-ctl-unit";
file = "${proxyCtl}/test_proxy_ctl.py";
env = singBox;
};
# proxy-suitectl, nix-on-droid's service manager: real processes restarted, timed and stopped.
proxy-suite-supervisor-unit = {
file = "${proxyCtl}/test_proxy_supervisor.py";
env.HOME = "\"$TMPDIR\"";
};
# proxy_export: the running config made portable, and sing-box still accepts it.
proxy-export-unit = {
drv = "proxy-suite-proxy-export-unit";
file = "${proxyCtl}/test_proxy_export.py";
env = singBox // {
PYTHONPATH = "${proxyCtl}";
};
};
# proxy-tui driven headless: keys turn into the right proxy-ctl argv.
proxy-tui-unit = {
drv = "proxy-suite-proxy-tui-unit";
file = "${proxyCtl}/test_proxy_tui.py";
python = pkgs.python3.withPackages (ps: [ ps.textual ]);
env.PYTHONPATH = "${proxyCtl}";
};
# proxy_model: the status strip, tab loads and the tray menu tree, without a UI toolkit.
proxy-model-unit = {
drv = "proxy-suite-proxy-model-unit";
file = "${proxyCtl}/test_proxy_model.py";
env.PYTHONPATH = "${proxyCtl}";
};
# proxy_gui and proxy_sni import against GTK4/libadwaita, the D-Bus interfaces parse, and the
# tray menu serializes to dbusmenu's layout type. No display needed.
proxy-gui-smoke = {
drv = "proxy-suite-proxy-gui-smoke";
file = "${proxyCtl}/test_proxy_gui.py";
python = pkgs.python3.withPackages (ps: [ ps.pygobject3 ]);
extraInputs = [ pkgs.gobject-introspection ];
buildInputs = [
pkgs.gtk4
pkgs.libadwaita
];
env.PYTHONPATH = "${proxyCtl}";
};
}
+18 -91
View File
@@ -8,6 +8,22 @@
controlModuleSource, controlModuleSource,
}: }:
let
# Every proxy-ctl CLI check runs against the same disabled-feature defaults; only the
# files and the feature under test differ.
perAppRoutingOff = ''
PER_APP_ROUTING_ENABLED="0" \
PER_APP_ROUTING_PROXYCHAINS_ENABLED="0" \
PER_APP_ROUTING_TUN_ENABLED="0" \
PER_APP_ROUTING_TPROXY_ENABLED="0" \
PER_APP_ROUTING_ZAPRET_ENABLED="0" \
PER_APP_ROUTING_PROFILES_FILE="$PWD/profiles.json" \
PROXYCHAINS_CONFIG="$PWD/proxychains.conf" \
PROXYCHAINS_QUIET_ARG="" \
ROUTE_MODE_STATE_FILE="$PWD/route-mode" \
DEFAULT_ROUTE_MODE="blacklist" \
'';
in
{ {
no-secrets = pkgs.runCommand "proxy-suite-no-secrets-check" { } '' no-secrets = pkgs.runCommand "proxy-suite-no-secrets-check" { } ''
repo_root=${../../.} repo_root=${../../.}
@@ -65,17 +81,7 @@
SUB_CACHE_DIR="$PWD/cache" \ SUB_CACHE_DIR="$PWD/cache" \
CLASH_API="http://127.0.0.1:9090" \ CLASH_API="http://127.0.0.1:9090" \
SELECTION="first" \ SELECTION="first" \
PER_APP_ROUTING_ENABLED="0" \ ${perAppRoutingOff} python3 "$proxy_ctl" proxy subs list > output
PER_APP_ROUTING_PROXYCHAINS_ENABLED="0" \
PER_APP_ROUTING_TUN_ENABLED="0" \
PER_APP_ROUTING_TPROXY_ENABLED="0" \
PER_APP_ROUTING_ZAPRET_ENABLED="0" \
PER_APP_ROUTING_PROFILES_FILE="$PWD/profiles.json" \
PROXYCHAINS_CONFIG="$PWD/proxychains.conf" \
PROXYCHAINS_QUIET_ARG="" \
ROUTE_MODE_STATE_FILE="$PWD/route-mode" \
DEFAULT_ROUTE_MODE="blacklist" \
python3 "$proxy_ctl" proxy subs list > output
# The old spelling still dispatches. # The old spelling still dispatches.
env SUB_TAGS_FILE="$PWD/tags.json" SUB_CACHE_DIR="$PWD/cache" \ env SUB_TAGS_FILE="$PWD/tags.json" SUB_CACHE_DIR="$PWD/cache" \
python3 "$proxy_ctl" subscription list | cmp - output python3 "$proxy_ctl" subscription list | cmp - output
@@ -137,17 +143,7 @@
USER_CONTROL_GROUP="proxy-suite" \ USER_CONTROL_GROUP="proxy-suite" \
CLASH_API="http://127.0.0.1:1" \ CLASH_API="http://127.0.0.1:1" \
SELECTION="urltest" \ SELECTION="urltest" \
PER_APP_ROUTING_ENABLED="0" \ ${perAppRoutingOff} python3 "$proxy_ctl" "$@"
PER_APP_ROUTING_PROXYCHAINS_ENABLED="0" \
PER_APP_ROUTING_TUN_ENABLED="0" \
PER_APP_ROUTING_TPROXY_ENABLED="0" \
PER_APP_ROUTING_ZAPRET_ENABLED="0" \
PER_APP_ROUTING_PROFILES_FILE="$PWD/profiles.json" \
PROXYCHAINS_CONFIG="$PWD/proxychains.conf" \
PROXYCHAINS_QUIET_ARG="" \
ROUTE_MODE_STATE_FILE="$PWD/route-mode" \
DEFAULT_ROUTE_MODE="blacklist" \
python3 "$proxy_ctl" "$@"
} }
# Listing works from the inventory alone, with no Clash API answering. # Listing works from the inventory alone, with no Clash API answering.
@@ -453,75 +449,6 @@
touch "$out" touch "$out"
''; '';
# proxy_ctl.py's function-level tests: the probe verdict table and exit walk,
# autoProxy learn/queue, inbound stats and subscriptions, apps run.
proxy-ctl-unit =
pkgs.runCommand "proxy-suite-proxy-ctl-unit-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export SING_BOX=${pkgs.sing-box}/bin/sing-box
export PYTHONDONTWRITEBYTECODE=1
python ${../../pkgs/proxy-ctl}/test_proxy_ctl.py
touch "$out"
'';
# proxy-suitectl, nix-on-droid's service manager: real processes restarted, timed and stopped.
proxy-suite-supervisor-unit =
pkgs.runCommand "proxy-suite-supervisor-unit-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1 HOME="$TMPDIR"
python ${../../pkgs/proxy-ctl}/test_proxy_supervisor.py
touch "$out"
'';
# proxy_export: the running config made portable, and sing-box still accepts it.
proxy-export-unit =
pkgs.runCommand "proxy-suite-proxy-export-unit-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export SING_BOX=${pkgs.sing-box}/bin/sing-box
export PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=${../../pkgs/proxy-ctl}
python ${../../pkgs/proxy-ctl}/test_proxy_export.py
touch "$out"
'';
# proxy-tui driven headless: keys turn into the right proxy-ctl argv.
proxy-tui-unit =
pkgs.runCommand "proxy-suite-proxy-tui-unit-check"
{ nativeBuildInputs = [ (pkgs.python3.withPackages (ps: [ ps.textual ])) ]; }
''
export PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=${../../pkgs/proxy-ctl}
python ${../../pkgs/proxy-ctl}/test_proxy_tui.py
touch "$out"
'';
# proxy_model: the status strip, tab loads and the tray menu tree, without a UI toolkit.
proxy-model-unit =
pkgs.runCommand "proxy-suite-proxy-model-unit-check" { nativeBuildInputs = [ pkgs.python3 ]; }
''
export PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=${../../pkgs/proxy-ctl}
python ${../../pkgs/proxy-ctl}/test_proxy_model.py
touch "$out"
'';
# proxy_gui and proxy_sni import against GTK4/libadwaita, the D-Bus interfaces parse,
# and the tray menu serializes to dbusmenu's layout type. No display needed.
proxy-gui-smoke =
pkgs.runCommand "proxy-suite-proxy-gui-smoke-check"
{
nativeBuildInputs = [
(pkgs.python3.withPackages (ps: [ ps.pygobject3 ]))
pkgs.gobject-introspection
];
buildInputs = [
pkgs.gtk4
pkgs.libadwaita
];
}
''
export PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=${../../pkgs/proxy-ctl}
python ${../../pkgs/proxy-ctl}/test_proxy_gui.py
touch "$out"
'';
# autoProxy slowness routing: sampler and judge. # autoProxy slowness routing: sampler and judge.
autoproxy-slowness = autoproxy-slowness =
pkgs.runCommand "proxy-suite-autoproxy-slowness-check" { nativeBuildInputs = [ pkgs.jq ]; } pkgs.runCommand "proxy-suite-autoproxy-slowness-check" { nativeBuildInputs = [ pkgs.jq ]; }
+9 -11
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -9,6 +10,7 @@
}: }:
let let
inherit (checkLib) ok startScript;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
routeModeFixture = evalProxySuite [ routeModeFixture = evalProxySuite [
@@ -38,9 +40,7 @@ let
}; };
} }
]; ];
routeModeStartScript = generated.readDerivation ( routeModeStartScript = startScript routeModeFixture;
routeModeFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
routeModeBackendJqFilter = routeModeBackendJqFilter =
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
{ {
@@ -81,11 +81,9 @@ in
) )
# proxy-ctl help/status exposes default plus the explicit route modes. # proxy-ctl help/status exposes default plus the explicit route modes.
( (ok (
assert pkgs.lib.hasInfix "proxy mode [default|whitelist|blacklist|all-proxy|all-bypass]" pkgs.lib.hasInfix "proxy mode [default|whitelist|blacklist|all-proxy|all-bypass]" minimalProxyCtlScript
minimalProxyCtlScript; ))
true
)
# The socks start script includes every override branch and uses volatile state. # The socks start script includes every override branch and uses volatile state.
( (
@@ -118,9 +116,9 @@ in
in in
assert !(setterSvc.serviceConfig ? RuntimeDirectory); assert !(setterSvc.serviceConfig ? RuntimeDirectory);
assert pkgs.lib.hasInfix "/run/proxy-suite/route-mode" routeModeSetterScript; assert pkgs.lib.hasInfix "/run/proxy-suite/route-mode" routeModeSetterScript;
assert pkgs.lib.hasInfix "default)" routeModeSetterScript; # One case arm lists every mode the setter accepts.
assert pkgs.lib.hasInfix "all-proxy)" routeModeSetterScript; assert pkgs.lib.hasInfix "default | whitelist | blacklist | all-proxy | all-bypass)"
assert pkgs.lib.hasInfix "all-bypass)" routeModeSetterScript; routeModeSetterScript;
true true
) )
+28 -58
View File
@@ -1,6 +1,7 @@
# nixosModules.server as the installer writes it: once for an IP certificate, once for # nixosModules.server as the installer writes it: once for an IP certificate, once for
# a domain. # a domain.
{ {
checkLib,
pkgs, pkgs,
system, system,
nixpkgs, nixpkgs,
@@ -9,6 +10,7 @@
}: }:
let let
inherit (checkLib) ok;
inherit (pkgs) lib; inherit (pkgs) lib;
serverModule = import ../../deploy/server-module.nix { inherit proxySuiteModule; }; serverModule = import ../../deploy/server-module.nix { inherit proxySuiteModule; };
@@ -66,14 +68,8 @@ let
in in
{ {
assertions = [ assertions = [
( (ok (failedAssertions ipServer == [ ]))
assert failedAssertions ipServer == [ ]; (ok (failedAssertions domainServer == [ ]))
true
)
(
assert failedAssertions domainServer == [ ];
true
)
( (
assert assert
@@ -95,14 +91,8 @@ in
(listener ipSpec "vless-tls").tls.certificateFile == "/var/lib/acme/203.0.113.10/fullchain.pem"; (listener ipSpec "vless-tls").tls.certificateFile == "/var/lib/acme/203.0.113.10/fullchain.pem";
true true
) )
( (ok ((listener domainSpec "vless-ws").tls.keyFile == "/var/lib/acme/vpn.example.com/key.pem"))
assert (listener domainSpec "vless-ws").tls.keyFile == "/var/lib/acme/vpn.example.com/key.pem"; (ok ((listener ipSpec "vless-ws").transport.path == "/3f9a1c07b2e4"))
true
)
(
assert (listener ipSpec "vless-ws").transport.path == "/3f9a1c07b2e4";
true
)
( (
assert assert
(lib.head (listener ipSpec "vless-tls").users).uuidFile == "/var/lib/proxy-suite-server/uuid"; (lib.head (listener ipSpec "vless-tls").users).uuidFile == "/var/lib/proxy-suite-server/uuid";
@@ -110,28 +100,13 @@ in
) )
# IP certificates exist only in the short-lived profile. # IP certificates exist only in the short-lived profile.
( (ok (ipCert.profile == "shortlived" && domainCert.profile == null))
assert ipCert.profile == "shortlived" && domainCert.profile == null; (ok (ipCert.group == "proxy-suite-daemon"))
true (ok (ipServer.config.services.proxy-suite.inbounds.serverAddress == "203.0.113.10"))
) (ok (domainServer.config.services.proxy-suite.inbounds.serverAddress == "vpn.example.com"))
(
assert ipCert.group == "proxy-suite-daemon";
true
)
(
assert ipServer.config.services.proxy-suite.inbounds.serverAddress == "203.0.113.10";
true
)
(
assert domainServer.config.services.proxy-suite.inbounds.serverAddress == "vpn.example.com";
true
)
# A /32 with a gateway outside it only works on-link. # A /32 with a gateway outside it only works on-link.
( (ok ((uplink ipServer).address == [ "203.0.113.10/32" ]))
assert (uplink ipServer).address == [ "203.0.113.10/32" ];
true
)
( (
assert assert
(uplink ipServer).routes == [ (uplink ipServer).routes == [
@@ -142,31 +117,21 @@ in
]; ];
true true
) )
( (ok ((uplink domainServer).networkConfig.DHCP == "yes" && (uplink domainServer).address == [ ]))
assert (uplink domainServer).networkConfig.DHCP == "yes" && (uplink domainServer).address == [ ];
true
)
( (ok (
assert lib.all (p: builtins.elem p ipServer.config.networking.firewall.allowedTCPPorts) [ lib.all (p: builtins.elem p ipServer.config.networking.firewall.allowedTCPPorts) [
80 80
443 443
8443 8443
2053 2053
22 22
]; ]
true ))
) (ok (ipServer.config.services.openssh.settings.PermitRootLogin == "no"))
(
assert ipServer.config.services.openssh.settings.PermitRootLogin == "no";
true
)
# onion.enable: every listener behind the onion service, and nothing opened for it. # onion.enable: every listener behind the onion service, and nothing opened for it.
( (ok (failedAssertions onionServer == [ ]))
assert failedAssertions onionServer == [ ];
true
)
( (
assert assert
lib.sort (a: b: a < b) onionSpec.onionListeners == [ lib.sort (a: b: a < b) onionSpec.onionListeners == [
@@ -181,11 +146,9 @@ in
!(ipServer.config.systemd.services ? proxy-suite-tor) && (ipSpec.onionListeners or [ ]) == [ ]; !(ipServer.config.systemd.services ? proxy-suite-tor) && (ipSpec.onionListeners or [ ]) == [ ];
true true
) )
( (ok (
assert builtins.elem "proxy-suite-tor.service" builtins.elem "proxy-suite-tor.service" onionServer.config.systemd.services.proxy-suite-inbounds.after
onionServer.config.systemd.services.proxy-suite-inbounds.after; ))
true
)
( (
assert assert
onionServer.config.networking.firewall.allowedTCPPorts onionServer.config.networking.firewall.allowedTCPPorts
@@ -198,5 +161,12 @@ in
&& !(lib.hasInfix "--onion" ipServer.config.services.getty.helpLine); && !(lib.hasInfix "--onion" ipServer.config.services.getty.helpLine);
true true
) )
# The console banner names the server and the admin account, interpolated: an escaped
# ''${...} used to reach the login screen verbatim.
(
assert lib.hasInfix "proxy-suite server 203.0.113.10." ipServer.config.services.getty.helpLine;
assert !(lib.hasInfix "\${" ipServer.config.services.getty.helpLine);
true
)
]; ];
} }
+101 -227
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -8,6 +9,7 @@
}: }:
let let
inherit (checkLib) ok mkProxySuite startScript;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
testHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; testHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
@@ -22,29 +24,22 @@ let
builtins.unsafeDiscardStringContext "${pkgs.writeText "proxy-suite-core" (builtins.toJSON value)}"; builtins.unsafeDiscardStringContext "${pkgs.writeText "proxy-suite-core" (builtins.toJSON value)}";
# SingBox dials SSH natively: no unit, no local SOCKS listener. # SingBox dials SSH natively: no unit, no local SOCKS listener.
sshNativeSingBox = evalProxySuite [ sshNativeSingBox = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; sshProxy = {
services.proxy-suite = { enable = true;
enable = true; server.user = "root";
sshProxy = { server.host = "ssh.example.com";
enable = true; asOutbound = true;
server.user = "root"; identityFile = "/run/secrets/ssh-key";
server.host = "ssh.example.com"; hostKey = [ testHostKey ];
asOutbound = true; };
identityFile = "/run/secrets/ssh-key"; proxy = {
hostKey = [ testHostKey ]; enable = true;
}; backend = "sing-box";
proxy = { };
enable = true; };
backend = "sing-box"; sshNativeSingBoxStart = startScript sshNativeSingBox;
};
};
}
];
sshNativeSingBoxStart = generated.readDerivation (
sshNativeSingBox.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
expectedNativeSingBoxOutbound = expectedOutboundFile { expectedNativeSingBoxOutbound = expectedOutboundFile {
type = "ssh"; type = "ssh";
tag = "ssh-proxy"; tag = "ssh-proxy";
@@ -56,29 +51,22 @@ let
}; };
# hostKeyFile keys are injected at start, not baked into the JSON. # hostKeyFile keys are injected at start, not baked into the JSON.
sshHostKeyFile = evalProxySuite [ sshHostKeyFile = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; sshProxy = {
services.proxy-suite = { enable = true;
enable = true; server.user = "root";
sshProxy = { server.host = "ssh.example.com";
enable = true; server.port = 2222;
server.user = "root"; asOutbound = true;
server.host = "ssh.example.com"; hostKeyFile = "/run/secrets/ssh-known-hosts";
server.port = 2222; };
asOutbound = true; proxy = {
hostKeyFile = "/run/secrets/ssh-known-hosts"; enable = true;
}; backend = "sing-box";
proxy = { };
enable = true; };
backend = "sing-box"; sshHostKeyFileStart = startScript sshHostKeyFile;
};
};
}
];
sshHostKeyFileStart = generated.readDerivation (
sshHostKeyFile.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
# asOutbound = false: a standalone tunnel, so the OpenSSH unit exists even on SingBox. # asOutbound = false: a standalone tunnel, so the OpenSSH unit exists even on SingBox.
sshStandalone = evalProxySuite [ sshStandalone = evalProxySuite [
@@ -114,38 +102,27 @@ let
]; ];
standaloneService = sshStandalone.config.systemd.services."proxy-suite-ssh-proxy"; standaloneService = sshStandalone.config.systemd.services."proxy-suite-ssh-proxy";
standaloneStartScript = generated.readDerivation standaloneService.serviceConfig.ExecStart; standaloneStartScript = generated.readDerivation standaloneService.serviceConfig.ExecStart;
sshStandaloneStart = generated.readDerivation ( sshStandaloneStart = startScript sshStandalone;
sshStandalone.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
unchanged = evalProxySuite [ baseModule ]; unchanged = evalProxySuite [ baseModule ];
unchangedStart = generated.readDerivation ( unchangedStart = startScript unchanged;
unchanged.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
# XRay keeps the unit and proxies through its listener, domainStrategy on sockopt. # XRay keeps the unit and proxies through its listener, domainStrategy on sockopt.
sshXray = evalProxySuite [ sshXray = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; sshProxy = {
services.proxy-suite = { enable = true;
enable = true; server.user = "proxy";
sshProxy = { server.host = "ssh.example.com";
enable = true; asOutbound = true;
server.user = "proxy"; domainStrategy = "prefer_ipv4";
server.host = "ssh.example.com"; };
asOutbound = true; proxy = {
domainStrategy = "prefer_ipv4"; enable = true;
}; backend = "xray";
proxy = { };
enable = true; };
backend = "xray"; sshXrayStart = startScript sshXray;
};
};
}
];
sshXrayStart = generated.readDerivation (
sshXray.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
xrayService = sshXray.config.systemd.services."proxy-suite-ssh-proxy"; xrayService = sshXray.config.systemd.services."proxy-suite-ssh-proxy";
xrayStartScript = generated.readDerivation xrayService.serviceConfig.ExecStart; xrayStartScript = generated.readDerivation xrayService.serviceConfig.ExecStart;
expectedXrayOutbound = expectedOutboundFile { expectedXrayOutbound = expectedOutboundFile {
@@ -161,28 +138,21 @@ let
}; };
}; };
sshHybrid = evalProxySuite [ sshHybrid = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; sshProxy = {
services.proxy-suite = { enable = true;
enable = true; server.user = "proxy";
sshProxy = { server.host = "ssh.example.com";
enable = true; asOutbound = true;
server.user = "proxy"; hostKey = [ testHostKey ];
server.host = "ssh.example.com"; };
asOutbound = true; proxy = {
hostKey = [ testHostKey ]; enable = true;
}; backend = "hybrid";
proxy = { };
enable = true; };
backend = "hybrid"; sshHybridStart = startScript sshHybrid;
};
};
}
];
sshHybridStart = generated.readDerivation (
sshHybrid.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
expectedHybridOutbound = expectedOutboundFile { expectedHybridOutbound = expectedOutboundFile {
type = "ssh"; type = "ssh";
tag = "ssh-proxy"; tag = "ssh-proxy";
@@ -219,9 +189,7 @@ let
}; };
} }
]; ];
sshSelectorStart = generated.readDerivation ( sshSelectorStart = startScript sshSelector;
sshSelector.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
sshUrltest = evalProxySuite [ sshUrltest = evalProxySuite [
{ {
@@ -248,9 +216,7 @@ let
}; };
} }
]; ];
sshUrltestStart = generated.readDerivation ( sshUrltestStart = startScript sshUrltest;
sshUrltest.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
sshRouting = evalProxySuite [ sshRouting = evalProxySuite [
{ {
@@ -339,15 +305,9 @@ let
]; ];
assertions = [ assertions = [
( (ok (sshNativeSingBox.config.services.proxy-suite.proxy.outbounds == [ ]))
assert sshNativeSingBox.config.services.proxy-suite.proxy.outbounds == [ ];
true
)
# No OpenSSH unit and no ordering against one: sing-box dials SSH in-process. # No OpenSSH unit and no ordering against one: sing-box dials SSH in-process.
( (ok (!(sshNativeSingBox.config.systemd.services ? "proxy-suite-ssh-proxy")))
assert !(sshNativeSingBox.config.systemd.services ? "proxy-suite-ssh-proxy");
true
)
( (
assert assert
sshNativeSingBox.config.systemd.services."proxy-suite-socks".after == [ sshNativeSingBox.config.systemd.services."proxy-suite-socks".after == [
@@ -372,24 +332,12 @@ let
true true
) )
# The global local-resolve route rule is gone; the native outbound resolves. # The global local-resolve route rule is gone; the native outbound resolves.
( (ok (!(pkgs.lib.hasInfix "\"resolve\"" sshNativeSingBoxStart)))
assert !(pkgs.lib.hasInfix "\"resolve\"" sshNativeSingBoxStart);
true
)
# Non-default port has to be looked up as "[host]:port" in known_hosts. # Non-default port has to be looked up as "[host]:port" in known_hosts.
( (ok (pkgs.lib.hasInfix "ssh-keygen -F '[ssh.example.com]:2222'" sshHostKeyFileStart))
assert pkgs.lib.hasInfix "ssh-keygen -F '[ssh.example.com]:2222'" sshHostKeyFileStart; (ok (pkgs.lib.hasInfix "'.host_key = \$hk'" sshHostKeyFileStart))
true (ok (pkgs.lib.hasInfix "/run/secrets/ssh-known-hosts" sshHostKeyFileStart))
)
(
assert pkgs.lib.hasInfix "'.host_key = \$hk'" sshHostKeyFileStart;
true
)
(
assert pkgs.lib.hasInfix "/run/secrets/ssh-known-hosts" sshHostKeyFileStart;
true
)
# The keys must not be baked into the store-resident outbound JSON. # The keys must not be baked into the store-resident outbound JSON.
( (
assert assert
@@ -400,56 +348,21 @@ let
) )
# Standalone tunnel: unit is created, but nothing is wired as an outbound. # Standalone tunnel: unit is created, but nothing is wired as an outbound.
( (ok (sshStandalone.config.systemd.services ? "proxy-suite-ssh-proxy"))
assert sshStandalone.config.systemd.services ? "proxy-suite-ssh-proxy"; (ok (!(pkgs.lib.hasInfix "ssh-proxy" sshStandaloneStart)))
true (ok (standaloneService.serviceConfig.User == "proxy"))
) (ok (!(standaloneService.serviceConfig ? SocketMark)))
(
assert !(pkgs.lib.hasInfix "ssh-proxy" sshStandaloneStart);
true
)
(
assert standaloneService.serviceConfig.User == "proxy";
true
)
(
assert !(standaloneService.serviceConfig ? SocketMark);
true
)
# Hardening: a half-open tunnel must be detected and always restarted. # Hardening: a half-open tunnel must be detected and always restarted.
( (ok (standaloneService.serviceConfig.Restart == "always"))
assert standaloneService.serviceConfig.Restart == "always"; (ok (standaloneService.serviceConfig.LimitNOFILE == 65536))
true (ok (standaloneService.startLimitIntervalSec == 0))
) (ok (pkgs.lib.hasInfix "ServerAliveInterval=15" standaloneStartScript))
( (ok (pkgs.lib.hasInfix "ServerAliveCountMax=3" standaloneStartScript))
assert standaloneService.serviceConfig.LimitNOFILE == 65536; (ok (pkgs.lib.hasInfix "ConnectTimeout=10" standaloneStartScript))
true (ok (pkgs.lib.hasInfix "IPQoS=throughput" standaloneStartScript))
) (ok (
( pkgs.lib.hasInfix ''UserKnownHostsFile="$CREDENTIALS_DIRECTORY/known_hosts"'' standaloneStartScript
assert standaloneService.startLimitIntervalSec == 0; ))
true
)
(
assert pkgs.lib.hasInfix "ServerAliveInterval=15" standaloneStartScript;
true
)
(
assert pkgs.lib.hasInfix "ServerAliveCountMax=3" standaloneStartScript;
true
)
(
assert pkgs.lib.hasInfix "ConnectTimeout=10" standaloneStartScript;
true
)
(
assert pkgs.lib.hasInfix "IPQoS=throughput" standaloneStartScript;
true
)
(
assert pkgs.lib.hasInfix ''UserKnownHostsFile="$CREDENTIALS_DIRECTORY/known_hosts"''
standaloneStartScript;
true
)
# Secrets reach the unprivileged user as credentials. # Secrets reach the unprivileged user as credentials.
( (
assert assert
@@ -460,20 +373,11 @@ let
true true
) )
( (ok (!(unchanged.config.systemd.services ? "proxy-suite-ssh-proxy")))
assert !(unchanged.config.systemd.services ? "proxy-suite-ssh-proxy"); (ok (!(pkgs.lib.hasInfix "ssh-proxy" unchangedStart)))
true
)
(
assert !(pkgs.lib.hasInfix "ssh-proxy" unchangedStart);
true
)
# XRay keeps the unit and orders the backend behind it. # XRay keeps the unit and orders the backend behind it.
( (ok (sshXray.config.systemd.services ? "proxy-suite-ssh-proxy"))
assert sshXray.config.systemd.services ? "proxy-suite-ssh-proxy";
true
)
( (
assert assert
sshXray.config.systemd.services."proxy-suite-socks".after == [ sshXray.config.systemd.services."proxy-suite-socks".after == [
@@ -490,50 +394,20 @@ let
]; ];
true true
) )
( (ok (xrayService.serviceConfig.Restart == "always"))
assert xrayService.serviceConfig.Restart == "always"; (ok (pkgs.lib.hasInfix "ServerAliveInterval=15" xrayStartScript))
true
)
(
assert pkgs.lib.hasInfix "ServerAliveInterval=15" xrayStartScript;
true
)
# prefer_ipv4 maps onto XRay's "IPv4 first, fall back to IPv6". # prefer_ipv4 maps onto XRay's "IPv4 first, fall back to IPv6".
( (ok (pkgs.lib.hasInfix expectedXrayOutbound sshXrayStart))
assert pkgs.lib.hasInfix expectedXrayOutbound sshXrayStart;
true
)
# Hybrid routes the tunnel through sing-box, so it gets the native shape. # Hybrid routes the tunnel through sing-box, so it gets the native shape.
( (ok (!(sshHybrid.config.systemd.services ? "proxy-suite-ssh-proxy")))
assert !(sshHybrid.config.systemd.services ? "proxy-suite-ssh-proxy"); (ok (pkgs.lib.hasInfix "_proxy_suite_add_sing_box_ob" sshHybridStart))
true (ok (pkgs.lib.hasInfix expectedHybridOutbound sshHybridStart))
)
(
assert pkgs.lib.hasInfix "_proxy_suite_add_sing_box_ob" sshHybridStart;
true
)
(
assert pkgs.lib.hasInfix expectedHybridOutbound sshHybridStart;
true
)
( (ok (pkgs.lib.hasInfix "selector" sshSelectorStart))
assert pkgs.lib.hasInfix "selector" sshSelectorStart; (ok (pkgs.lib.hasInfix "ssh-proxy" sshSelectorStart))
true (ok (pkgs.lib.hasInfix "# outbound: ssh-proxy (OpenSSH SOCKS5 listener)" sshUrltestStart))
) (ok (builtins.any (rule: (rule.outbound or null) == "ssh-proxy") (mkRoutingRules sshRouting)))
(
assert pkgs.lib.hasInfix "ssh-proxy" sshSelectorStart;
true
)
(
assert pkgs.lib.hasInfix "# outbound: ssh-proxy (OpenSSH SOCKS5 listener)" sshUrltestStart;
true
)
(
assert builtins.any (rule: (rule.outbound or null) == "ssh-proxy") (mkRoutingRules sshRouting);
true
)
] ]
++ invalidAssertions; ++ invalidAssertions;
in in
+8 -20
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkProxyCtlDerived, mkProxyCtlDerived,
@@ -6,7 +7,9 @@
}: }:
let let
inherit (checkLib) ok;
fixtures = import ./subscriptions-runtime/fixtures.nix { fixtures = import ./subscriptions-runtime/fixtures.nix {
inherit checkLib;
inherit inherit
evalProxySuite evalProxySuite
mkProxyCtlDerived mkProxyCtlDerived
@@ -28,10 +31,7 @@ in
{ {
assertions = [ assertions = [
# Basic config is accepted. # Basic config is accepted.
( (ok (subscriptionOnlyFixture.config.services.proxy-suite.proxy.subscriptions != [ ]))
assert subscriptionOnlyFixture.config.services.proxy-suite.proxy.subscriptions != [ ];
true
)
# Wrapper exposes tags through a JSON file, not shell word splitting. # Wrapper exposes tags through a JSON file, not shell word splitting.
( (
@@ -42,14 +42,8 @@ in
) )
# Update service and timer are created when subscriptions are configured. # Update service and timer are created when subscriptions are configured.
( (ok (subscriptionOnlyFixture.config.systemd.services ? "proxy-suite-subscription-update"))
assert subscriptionOnlyFixture.config.systemd.services ? "proxy-suite-subscription-update"; (ok (subscriptionOnlyFixture.config.systemd.timers ? "proxy-suite-subscription-update"))
true
)
(
assert subscriptionOnlyFixture.config.systemd.timers ? "proxy-suite-subscription-update";
true
)
# A oneshot left active would swallow every later timer run. # A oneshot left active would swallow every later timer run.
( (
assert assert
@@ -176,14 +170,8 @@ in
# The update service and timer exist whenever the proxy does, because a # The update service and timer exist whenever the proxy does, because a
# subscription can be added at runtime after the rebuild. # subscription can be added at runtime after the rebuild.
( (ok (minimal.config.systemd.services ? "proxy-suite-subscription-update"))
assert minimal.config.systemd.services ? "proxy-suite-subscription-update"; (ok (minimal.config.systemd.timers ? "proxy-suite-subscription-update"))
true
)
(
assert minimal.config.systemd.timers ? "proxy-suite-subscription-update";
true
)
# Runtime spool dirs are root-only unless userControl grants outbounds (see user-control.nix). # Runtime spool dirs are root-only unless userControl grants outbounds (see user-control.nix).
( (
@@ -1,9 +1,11 @@
{ {
checkLib,
evalProxySuite, evalProxySuite,
mkProxyCtlDerived, mkProxyCtlDerived,
}: }:
let let
inherit (checkLib) startScript unitScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
subscriptionOnlyFixture = evalProxySuite [ subscriptionOnlyFixture = evalProxySuite [
@@ -60,9 +62,7 @@ let
}; };
} }
]; ];
subscriptionWithStaticStartScript = generated.readDerivation ( subscriptionWithStaticStartScript = startScript subscriptionWithStaticFixture;
subscriptionWithStaticFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
subscriptionFirstSelectionFixture = evalProxySuite [ subscriptionFirstSelectionFixture = evalProxySuite [
{ {
@@ -83,9 +83,7 @@ let
}; };
} }
]; ];
subscriptionFirstSelectionStartScript = generated.readDerivation ( subscriptionFirstSelectionStartScript = startScript subscriptionFirstSelectionFixture;
subscriptionFirstSelectionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
subscriptionPerAppTunFixture = evalProxySuite [ subscriptionPerAppTunFixture = evalProxySuite [
{ {
@@ -109,9 +107,7 @@ let
}; };
} }
]; ];
subscriptionPerAppTunUpdateScript = generated.readDerivation ( subscriptionPerAppTunUpdateScript = unitScript subscriptionPerAppTunFixture "proxy-suite-subscription-update";
subscriptionPerAppTunFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
);
in in
{ {
inherit inherit
+3 -4
View File
@@ -1,10 +1,12 @@
{ {
checkLib,
evalProxySuite, evalProxySuite,
mkBadFixtureRaw, mkBadFixtureRaw,
mkFailingAssertions, mkFailingAssertions,
}: }:
let let
inherit (checkLib) ok;
proxyWithSubscriptions = subscriptions: { proxyWithSubscriptions = subscriptions: {
system.stateVersion = "26.05"; system.stateVersion = "26.05";
services.proxy-suite = { services.proxy-suite = {
@@ -71,9 +73,6 @@ in
]) ])
++ [ ++ [
# urlFile form is accepted. # urlFile form is accepted.
( (ok (subscriptionUrlFileFixture.config.services.proxy-suite.proxy.subscriptions != [ ]))
assert subscriptionUrlFileFixture.config.services.proxy-suite.proxy.subscriptions != [ ];
true
)
]; ];
} }
+3
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkBadFixtureRaw, mkBadFixtureRaw,
@@ -9,6 +10,7 @@
let let
runtimeChecks = import ./subscriptions-runtime.nix { runtimeChecks = import ./subscriptions-runtime.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -17,6 +19,7 @@ let
; ;
}; };
validationChecks = import ./subscriptions-validation.nix { validationChecks = import ./subscriptions-validation.nix {
inherit checkLib;
inherit inherit
evalProxySuite evalProxySuite
mkBadFixtureRaw mkBadFixtureRaw
+6 -12
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -13,7 +14,9 @@
}: }:
let let
inherit (checkLib) ok;
fixtures = import ./tg-ws-proxy/fixtures.nix { fixtures = import ./tg-ws-proxy/fixtures.nix {
inherit checkLib;
inherit inherit
evalProxySuite evalProxySuite
baseModule baseModule
@@ -38,18 +41,9 @@ let
in in
{ {
assertions = [ assertions = [
( (ok (tgSecretFile.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1"))
assert tgSecretFile.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1"; (ok (minimal.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1"))
true (ok (minimal.config.services.proxy-suite.tgWsProxy.dcIps == { }))
)
(
assert minimal.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1";
true
)
(
assert minimal.config.services.proxy-suite.tgWsProxy.dcIps == { };
true
)
# Upstream runtime flags are exposed as typed module options. # Upstream runtime flags are exposed as typed module options.
( (
+3 -3
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
mkRoutingRules, mkRoutingRules,
@@ -8,6 +9,7 @@
}: }:
let let
inherit (checkLib) unitScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
tgSecretFile = evalProxySuite [ tgSecretFile = evalProxySuite [
@@ -47,9 +49,7 @@ let
}; };
} }
]; ];
tgAllOptionsStartScript = generated.readDerivation ( tgAllOptionsStartScript = unitScript tgAllOptions "proxy-suite-tg-ws-proxy";
tgAllOptions.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig.ExecStart
);
tgWithGlobalTun = evalProxySuite [ tgWithGlobalTun = evalProxySuite [
baseModule baseModule
+33 -47
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkBadProxySuiteFixture, mkBadProxySuiteFixture,
@@ -12,6 +13,7 @@
}: }:
let let
inherit (checkLib) ok mkProxySuite;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
inherit (pkgs) lib; inherit (pkgs) lib;
inherit (lib) hasInfix; inherit (lib) hasInfix;
@@ -108,32 +110,27 @@ let
viaProxyStart = torStartOf viaProxy; viaProxyStart = torStartOf viaProxy;
viaProxyTor = (services viaProxy).proxy-suite-tor; viaProxyTor = (services viaProxy).proxy-suite-tor;
onion = evalProxySuite [ onion = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; tor = {
services.proxy-suite = { enable = true;
onionService = {
enable = true; enable = true;
tor = { secretKeyFile = "/run/secrets/hs_ed25519_secret_key";
enable = true;
onionService = {
enable = true;
secretKeyFile = "/run/secrets/hs_ed25519_secret_key";
};
};
inbounds = {
enable = true;
serverAddress = "vpn.example.com";
routing.via = "direct";
listeners.plain = listener;
listeners.shared = listener // {
port = 10444;
address = "127.0.0.1";
sharePort = 443;
};
};
}; };
} };
]; inbounds = {
enable = true;
serverAddress = "vpn.example.com";
routing.via = "direct";
listeners.plain = listener;
listeners.shared = listener // {
port = 10444;
address = "127.0.0.1";
sharePort = 443;
};
};
};
# An exit node: its clients' .onion names still reach Tor, through the local proxy. # An exit node: its clients' .onion names still reach Tor, through the local proxy.
exitInbounds = { exitInbounds = {
inbounds = { inbounds = {
@@ -326,8 +323,8 @@ in
!(lib.any (r: r.ruleTag or "" == "inbound-tor-onion") (mkInboundsConfig onion).routing.rules); !(lib.any (r: r.ruleTag or "" == "inbound-tor-onion") (mkInboundsConfig onion).routing.rules);
true true
) )
( (ok (
assert lib.all (f: failedAssertions f == [ ]) [ lib.all (f: failedAssertions f == [ ]) [
singBox singBox
xray xray
hybrid hybrid
@@ -335,25 +332,17 @@ in
bridges bridges
viaProxy viaProxy
onion onion
]; ]
true ))
)
# Every backend dials Tor's SOCKS listener as the "tor" outbound. # Every backend dials Tor's SOCKS listener as the "tor" outbound.
( (ok (
assert hasInfix ''{"server":"127.0.0.1","server_port":18530,"tag":"tor","type":"socks"}'' hasInfix ''{"server":"127.0.0.1","server_port":18530,"tag":"tor","type":"socks"}'' singBoxStart
singBoxStart; ))
true (ok (
) hasInfix ''{"protocol":"socks","settings":{"address":"127.0.0.1","port":18530},"tag":"tor"}'' xrayStart
( ))
assert hasInfix ''{"protocol":"socks","settings":{"address":"127.0.0.1","port":18530},"tag":"tor"}'' (ok (hasInfix ''"tag":"tor","type":"socks"'' hybridStart))
xrayStart;
true
)
(
assert hasInfix ''"tag":"tor","type":"socks"'' hybridStart;
true
)
# Only rules and detours reach it: never selected, tested, or used as an autoProxy exit. # Only rules and detours reach it: never selected, tested, or used as an autoProxy exit.
( (
assert assert
@@ -522,10 +511,7 @@ in
&& builtins.elem "proxy-suite-tor.service" onionInbounds.wants; && builtins.elem "proxy-suite-tor.service" onionInbounds.wants;
true true
) )
( (ok (!(onion.config.systemd.services ? proxy-suite-socks)))
assert !(onion.config.systemd.services ? proxy-suite-socks);
true
)
] ]
++ invalidAssertions; ++ invalidAssertions;
} }
+6 -5
View File
@@ -1,10 +1,12 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
}: }:
let let
inherit (checkLib) ok;
inherit (pkgs.lib) hasInfix; inherit (pkgs.lib) hasInfix;
mkFixture = mkFixture =
@@ -136,11 +138,10 @@ in
) )
# -- userControl: scopes without enable is refused, not silently ignored -- # -- userControl: scopes without enable is refused, not silently ignored --
( (ok (
assert builtins.any ( builtins.any (
a: !a.assertion && hasInfix "userControl.scopes is set" a.message a: !a.assertion && hasInfix "userControl.scopes is set" a.message
) scopesWithoutEnableFixture.config.assertions; ) scopesWithoutEnableFixture.config.assertions
true ))
)
]; ];
} }
+11 -14
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkBadProxySuiteFixture, mkBadProxySuiteFixture,
@@ -6,6 +7,7 @@
}: }:
let let
inherit (checkLib) mkProxySuite;
generated = import ./read-generated.nix; generated = import ./read-generated.nix;
inherit (pkgs.lib) hasInfix escapeShellArg; inherit (pkgs.lib) hasInfix escapeShellArg;
@@ -67,20 +69,15 @@ let
autoRegister = registerOf auto; autoRegister = registerOf auto;
generatorRegister = registerOf generator; generatorRegister = registerOf generator;
amneziaWg = evalProxySuite [ amneziaWg = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; amneziaWg.enable = true;
services.proxy-suite = { warp = {
enable = true; enable = true;
amneziaWg.enable = true; configFile = profile;
warp = { asAmneziaWg = true;
enable = true; };
configFile = profile; };
asAmneziaWg = true;
};
};
}
];
invalidAssertions = mkFailingAssertions mkBadProxySuiteFixture [ invalidAssertions = mkFailingAssertions mkBadProxySuiteFixture [
# Enabled but used for nothing. # Enabled but used for nothing.
+2
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -9,6 +10,7 @@
let let
fixtures = import ./xray-backend-features/fixtures.nix { fixtures = import ./xray-backend-features/fixtures.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
+11 -16
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -7,6 +8,7 @@
}: }:
let let
inherit (checkLib) mkProxySuite startScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
rawOutboundJson = rawOutboundJson =
(import ../../../modules/proxy-suite/service/script-blocks/outbounds.nix { (import ../../../modules/proxy-suite/service/script-blocks/outbounds.nix {
@@ -75,23 +77,16 @@ let
}; };
} }
]; ];
xraySubscriptionStartScript = generated.readDerivation ( xraySubscriptionStartScript = startScript xraySubscriptionFixture;
xraySubscriptionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
xrayRawStreamFixture = evalProxySuite [ xrayRawStreamFixture = mkProxySuite {
{ enable = true;
system.stateVersion = "26.05"; proxy = {
services.proxy-suite = { enable = true;
enable = true; backend = "xray";
proxy = { outbounds = [ xrayRawStreamDefinition ];
enable = true; };
backend = "xray"; };
outbounds = [ xrayRawStreamDefinition ];
};
};
}
];
xrayRawStreamOutbound = xrayRawStreamOutbound =
rawOutboundJson (builtins.head xrayRawStreamFixture.config.services.proxy-suite.proxy.outbounds) rawOutboundJson (builtins.head xrayRawStreamFixture.config.services.proxy-suite.proxy.outbounds)
"proxy" "proxy"
+3
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -10,6 +11,7 @@
let let
fixtures = import ./xray-backend-runtime/fixtures.nix { fixtures = import ./xray-backend-runtime/fixtures.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -100,6 +102,7 @@ let
; ;
}; };
tunChecks = import ./xray-backend-runtime/tun.nix { tunChecks = import ./xray-backend-runtime/tun.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
checkConstants checkConstants
+5 -9
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -8,6 +9,7 @@
}: }:
let let
inherit (checkLib) startScript unitScript;
generated = import ../read-generated.nix; generated = import ../read-generated.nix;
xrayModule = { xrayModule = {
@@ -49,18 +51,12 @@ let
xrayTproxyConfig = mkTProxyConfig xrayFixture; xrayTproxyConfig = mkTProxyConfig xrayFixture;
xrayTunConfig = mkTunConfig xrayFixture; xrayTunConfig = mkTunConfig xrayFixture;
xrayPerAppTunConfig = mkPerAppTunConfig xrayFixture; xrayPerAppTunConfig = mkPerAppTunConfig xrayFixture;
xrayStartScript = generated.readDerivation ( xrayStartScript = startScript xrayFixture;
xrayFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart xrayTunStartScript = unitScript xrayFixture "proxy-suite-tun";
);
xrayTunStartScript = generated.readDerivation (
xrayFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStart
);
xrayTunUpScript = generated.readDerivation ( xrayTunUpScript = generated.readDerivation (
xrayFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStartPost xrayFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStartPost
); );
xrayPerAppTunStartScript = generated.readDerivation ( xrayPerAppTunStartScript = unitScript xrayFixture "proxy-suite-per-app-tun";
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart
);
xrayPerAppTunUpScript = generated.readDerivation ( xrayPerAppTunUpScript = generated.readDerivation (
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStartPost xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStartPost
); );
+1
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
checkConstants, checkConstants,
xrayTunConfig, xrayTunConfig,
+3
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -13,6 +14,7 @@
let let
runtimeChecks = import ./xray-backend-runtime.nix { runtimeChecks = import ./xray-backend-runtime.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -24,6 +26,7 @@ let
; ;
}; };
featureChecks = import ./xray-backend-features.nix { featureChecks = import ./xray-backend-features.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
+3
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
mkTProxyConfig, mkTProxyConfig,
@@ -13,6 +14,7 @@
let let
xrayChecks = import ./xray-backend.nix { xrayChecks = import ./xray-backend.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
@@ -27,6 +29,7 @@ let
; ;
}; };
hybridChecks = import ./hybrid-backend.nix { hybridChecks = import ./hybrid-backend.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
+1
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
+2
View File
@@ -1,4 +1,5 @@
{ {
checkLib,
pkgs, pkgs,
evalProxySuite, evalProxySuite,
baseModule, baseModule,
@@ -40,6 +41,7 @@ let
; ;
zapretHostlistRoutingChecks = import ./zapret-hostlist-routing.nix { zapretHostlistRoutingChecks = import ./zapret-hostlist-routing.nix {
inherit checkLib;
inherit inherit
pkgs pkgs
evalProxySuite evalProxySuite
Loaded 100 of 109 files, more files were not shown because too many files have changed in this diff. Show more