refactor: remove duplication
This commit is contained in:
109 files changed
+2206
-3078
No files matched your search
@@ -1,75 +1,97 @@
|
||||
# Builds proxy-ctl from global proxy-suite state and per-app routing metadata.
|
||||
{
|
||||
packages,
|
||||
singBoxCfg,
|
||||
proxyCfg,
|
||||
perAppRoutingCfg,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
perAppZapretCfg,
|
||||
zapretEngine,
|
||||
zapretCutoffEnabled,
|
||||
constants,
|
||||
selectionMode,
|
||||
userControlCfg,
|
||||
subscriptionTagsFile,
|
||||
subscriptionCacheDir,
|
||||
perAppRoutingProfilesFile,
|
||||
proxychainsConfigFile,
|
||||
proxychainsQuietArg,
|
||||
routeModeStateFile,
|
||||
amneziaWgProfileNamesFile,
|
||||
proxyInboundsEnabled,
|
||||
proxyInboundsLinksFile,
|
||||
proxyInboundsSubscriptionsFile,
|
||||
proxyInboundsSubscriptionsBaseUrl,
|
||||
proxyInboundsXray,
|
||||
guiRefreshInterval,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
localProxy
|
||||
packages
|
||||
cfg
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
zapretEngine
|
||||
zapretCutoffEnabled
|
||||
constants
|
||||
selectionMode
|
||||
userControlCfg
|
||||
proxyInboundsCfg
|
||||
proxyInboundsEnabled
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
inherit (ctx.scripts)
|
||||
subscriptionTagsFile
|
||||
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 {
|
||||
clashApi = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
|
||||
selection = selectionMode;
|
||||
inherit
|
||||
guiRefreshInterval
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
routeModeStateFile
|
||||
amneziaWgProfileNamesFile
|
||||
guiRefreshInterval
|
||||
;
|
||||
defaultRouteMode = if (proxyCfg.routing.default == "proxy") then "blacklist" else "whitelist";
|
||||
perAppRoutingEnabled = if perAppRoutingCfg.enable then "1" else "0";
|
||||
perAppRoutingProxychainsEnabled = if perAppRoutingCfg.proxychains.enable then "1" else "0";
|
||||
perAppRoutingTunEnabled = if perAppRoutingTun.enable then "1" else "0";
|
||||
perAppRoutingTproxyEnabled = if perAppRoutingTproxy.enable then "1" else "0";
|
||||
perAppRoutingZapretEnabled = if perAppZapretCfg.enable then "1" else "0";
|
||||
zapretAutoEnabled = if zapretEngine == "zapret2" then "1" else "0";
|
||||
zapretStateDir = constants.zapret2StateDir;
|
||||
zapretCutoffEnabled = if zapretCutoffEnabled then "1" else "0";
|
||||
outboundInventoryFile = constants.outboundInventoryFile;
|
||||
runtimeOutboundsDir = constants.runtimeOutboundsDir;
|
||||
runtimeSubscriptionsDir = constants.runtimeSubscriptionsDir;
|
||||
userControlGroup = userControlCfg.group;
|
||||
inboundsEnabled = if proxyInboundsEnabled then "1" else "0";
|
||||
inboundsLinksFile = proxyInboundsLinksFile;
|
||||
inboundsStatsFile = constants.inboundStatsFile;
|
||||
inboundsXray = proxyInboundsXray;
|
||||
inboundsApi = "127.0.0.1:${toString constants.inboundStatsApiPort}";
|
||||
inboundsSubscriptionsFile = proxyInboundsSubscriptionsFile;
|
||||
inboundsSubscriptionsBaseUrl =
|
||||
if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl;
|
||||
autoProxyEnabled = if proxyCfg.autoProxy.enable then "1" else "0";
|
||||
autoProxyStateDir = constants.autoProxyStateDir;
|
||||
torControlSocket = constants.torControlSocket;
|
||||
inherit (constants) stateDir runtimeDir serviceManager;
|
||||
privileged = if constants.privileged then "1" else "0";
|
||||
supervisorCtl = if constants.serviceManager == "supervisor" then constants.systemctl else "";
|
||||
singBox = "${singBoxCfg.package}/bin/sing-box";
|
||||
localProxyUrl = "http://${
|
||||
if proxyCfg.listener.address == "0.0.0.0" then "127.0.0.1" else proxyCfg.listener.address
|
||||
}:${toString proxyCfg.listener.port}";
|
||||
env = {
|
||||
CLASH_API = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
|
||||
SELECTION = selectionMode;
|
||||
SUB_TAGS_FILE = toString subscriptionTagsFile;
|
||||
SUB_CACHE_DIR = subscriptionCacheDir;
|
||||
PER_APP_ROUTING_ENABLED = flag perAppRoutingCfg.enable;
|
||||
PER_APP_ROUTING_PROXYCHAINS_ENABLED = flag perAppRoutingCfg.proxychains.enable;
|
||||
PER_APP_ROUTING_TUN_ENABLED = flag perAppRoutingTun.enable;
|
||||
PER_APP_ROUTING_TPROXY_ENABLED = flag perAppRoutingTproxy.enable;
|
||||
PER_APP_ROUTING_ZAPRET_ENABLED = flag perAppZapretCfg.enable;
|
||||
PER_APP_ROUTING_PROFILES_FILE = toString perAppRoutingProfilesFile;
|
||||
PROXYCHAINS_CONFIG = toString proxychainsConfigFile;
|
||||
PROXYCHAINS_QUIET_ARG = lib.removeSuffix " " proxychainsQuietArg;
|
||||
ROUTE_MODE_STATE_FILE = routeModeStateFile;
|
||||
DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
|
||||
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
|
||||
INBOUNDS_ENABLED = flag proxyInboundsEnabled;
|
||||
INBOUNDS_LINKS_FILE = proxyInboundsLinksFile;
|
||||
INBOUNDS_STATS_FILE = constants.inboundStatsFile;
|
||||
INBOUNDS_XRAY = proxyInboundsXray;
|
||||
INBOUNDS_API = "127.0.0.1:${toString constants.inboundStatsApiPort}";
|
||||
INBOUNDS_SUBS_FILE = proxyInboundsSubscriptionsFile;
|
||||
INBOUNDS_SUB_BASE_URL =
|
||||
if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl;
|
||||
ZAPRET_AUTO_ENABLED = flag (zapretEngine == "zapret2");
|
||||
ZAPRET_STATE_DIR = constants.zapret2StateDir;
|
||||
ZAPRET_CUTOFF_ENABLED = flag zapretCutoffEnabled;
|
||||
OUTBOUND_INVENTORY_FILE = constants.outboundInventoryFile;
|
||||
RUNTIME_OUTBOUNDS_DIR = constants.runtimeOutboundsDir;
|
||||
RUNTIME_SUBS_DIR = constants.runtimeSubscriptionsDir;
|
||||
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;
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user