Files
proxy-suite-flake/modules/proxy-suite/config.nix
T
2026-09-15 17:52:49 +00:00

97 lines
2.3 KiB
Nix

# Build-time proxy backend configuration templates.
# Proxy outbounds are injected at service start time, not here.
{
lib,
pkgs,
cfg,
rules,
}:
let
derived = import ./derived.nix { inherit lib cfg; };
singBoxTemplates = import ./config-templates/sing-box.nix {
inherit
lib
derived
rules
;
};
xrayTemplates = import ./config-templates/xray.nix {
inherit
lib
derived
rules
;
};
inboundRules = import ./rules/proxy-inbounds.nix {
inherit lib;
inherit (derived) proxyInboundsCfg proxyInbounds;
inherit (rules) zapretDirectRules;
};
proxyInboundsTemplate = import ./config-templates/proxy-inbounds.nix {
inherit lib derived inboundRules;
inherit (xrayTemplates) mkDnsServer;
};
# Listener specification handed to build-inbound.py at service start. Secrets
# appear here only as paths; the script reads them at runtime.
proxyInboundsSpec = {
serverAddress = derived.proxyInboundsCfg.serverAddress;
shareLinks = derived.proxyInboundsCfg.shareLinks;
listeners = map (ib: {
inherit (ib) tag;
inherit (ib.listener)
type
port
sharePort
users
flow
method
serverPassword
serverPasswordFile
transport
tls
reality
xrayJson
jsonFile
;
listen = ib.listener.address;
}) derived.proxyInbounds;
};
selectedTemplates = if derived.pureXrayEnabled then xrayTemplates else singBoxTemplates;
routeModeRules =
if derived.pureXrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules;
tproxyFile = pkgs.writeText "proxy-suite-core" (
builtins.toJSON selectedTemplates.tproxy
);
tunFile = pkgs.writeText "proxy-suite-core" (
builtins.toJSON selectedTemplates.tun
);
perAppTunFile = pkgs.writeText "proxy-suite-core" (
builtins.toJSON selectedTemplates.perAppTun
);
routeModeRulesFile = pkgs.writeText "proxy-suite-core" (
builtins.toJSON routeModeRules
);
proxyInboundsFile = pkgs.writeText "proxy-suite-inbounds" (
builtins.toJSON proxyInboundsTemplate
);
proxyInboundsSpecFile = pkgs.writeText "proxy-suite-inbounds" (
builtins.toJSON proxyInboundsSpec
);
in
{
inherit
tproxyFile
tunFile
perAppTunFile
routeModeRulesFile
proxyInboundsFile
proxyInboundsSpecFile
;
}