97 lines
2.7 KiB
Nix
97 lines
2.7 KiB
Nix
# Per-app routing profile expansion and proxychains config.
|
|
{ ctx }:
|
|
|
|
let
|
|
inherit (ctx)
|
|
lib
|
|
pkgs
|
|
proxyCfg
|
|
perAppRoutingCfg
|
|
perAppRoutingTun
|
|
perAppRoutingTproxy
|
|
perAppZapretCfg
|
|
constants
|
|
;
|
|
inherit (constants) runtimeDir;
|
|
perAppRoutingProfileNames = map (profile: profile.name) perAppRoutingCfg.profiles;
|
|
defaultPerAppRoutingProfiles = lib.optionals perAppRoutingCfg.createDefaultProfiles (
|
|
lib.optionals perAppRoutingCfg.proxychains.enable [
|
|
{
|
|
name = "proxychains";
|
|
route = "proxychains";
|
|
}
|
|
]
|
|
++ lib.optionals perAppRoutingTun.enable [
|
|
{
|
|
name = "tun";
|
|
route = "tun";
|
|
}
|
|
]
|
|
++ lib.optionals perAppRoutingTproxy.enable [
|
|
{
|
|
name = "tproxy";
|
|
route = "tproxy";
|
|
}
|
|
]
|
|
++ lib.optionals perAppZapretCfg.enable [
|
|
{
|
|
name = "zapret";
|
|
route = "zapret";
|
|
}
|
|
]
|
|
);
|
|
effectivePerAppRoutingProfiles =
|
|
perAppRoutingCfg.profiles
|
|
++ builtins.filter (
|
|
profile: !(builtins.elem profile.name perAppRoutingProfileNames)
|
|
) defaultPerAppRoutingProfiles;
|
|
effectivePerAppRoutingProfileNames = map (profile: profile.name) effectivePerAppRoutingProfiles;
|
|
|
|
localProxyAuth = proxyCfg.listener.auth;
|
|
localProxyAuthEnabled = ctx.localProxy.authEnabled;
|
|
|
|
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app" (
|
|
builtins.toJSON effectivePerAppRoutingProfiles
|
|
);
|
|
|
|
proxychainsConfigFile =
|
|
if localProxyAuthEnabled then
|
|
"${runtimeDir}/proxy-suite-socks/proxychains.conf"
|
|
else
|
|
pkgs.writeText "proxy-suite-per-app" ''
|
|
strict_chain
|
|
${lib.optionalString perAppRoutingCfg.proxychains.quiet "quiet_mode"}
|
|
${lib.optionalString perAppRoutingCfg.proxychains.proxyDns "proxy_dns"}
|
|
tcp_read_time_out 15000
|
|
tcp_connect_time_out 8000
|
|
|
|
[ProxyList]
|
|
socks5 ${proxyCfg.listener.address} ${toString proxyCfg.listener.port}
|
|
'';
|
|
proxychainsQuietArg = lib.optionalString perAppRoutingCfg.proxychains.quiet "-q ";
|
|
|
|
hasProxychainsProfiles = builtins.any (
|
|
profile: profile.route == "proxychains"
|
|
) effectivePerAppRoutingProfiles;
|
|
hasTunProfiles = builtins.any (profile: profile.route == "tun") effectivePerAppRoutingProfiles;
|
|
hasTproxyProfiles = builtins.any (
|
|
profile: profile.route == "tproxy"
|
|
) effectivePerAppRoutingProfiles;
|
|
hasZapretProfiles = builtins.any (
|
|
profile: profile.route == "zapret"
|
|
) effectivePerAppRoutingProfiles;
|
|
in
|
|
{
|
|
inherit
|
|
effectivePerAppRoutingProfiles
|
|
effectivePerAppRoutingProfileNames
|
|
perAppRoutingProfilesFile
|
|
proxychainsConfigFile
|
|
proxychainsQuietArg
|
|
hasProxychainsProfiles
|
|
hasTunProfiles
|
|
hasTproxyProfiles
|
|
hasZapretProfiles
|
|
;
|
|
}
|