packages improvement
This commit is contained in:
11 files changed
+227
-98
No files matched your search
@@ -27,7 +27,7 @@
|
||||
inherit nixpkgs pkgsFor proxySuiteModule;
|
||||
};
|
||||
mkReadmeDoc = import ./nix/readme-doc.nix {
|
||||
inherit nixpkgs pkgsFor proxySuiteModule;
|
||||
inherit nixpkgs pkgsFor proxySuiteModule zapret;
|
||||
};
|
||||
in
|
||||
{
|
||||
@@ -39,6 +39,9 @@
|
||||
|
||||
overlays.default = final: prev: {
|
||||
inherit (import ./pkgs/default.nix { pkgs = final; })
|
||||
mkProxyCtl
|
||||
mkProxySuiteTray
|
||||
mkTgWsProxy
|
||||
tg-ws-proxy
|
||||
proxy-suite-tray
|
||||
;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
let
|
||||
cfg = config.services.proxy-suite;
|
||||
packages = import ../../pkgs/default.nix { inherit pkgs; };
|
||||
nftr = import ./nftables.nix { inherit lib pkgs cfg; };
|
||||
in
|
||||
{
|
||||
@@ -43,6 +44,7 @@ in
|
||||
config
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
inherit (configs) tproxyFile tunFile perAppTunFile;
|
||||
@@ -61,7 +63,11 @@ in
|
||||
}
|
||||
))
|
||||
|
||||
(lib.mkIf cfg.tgWsProxy.enable (import ./tg-ws-proxy.nix { inherit lib pkgs cfg; }))
|
||||
(lib.mkIf cfg.tgWsProxy.enable (
|
||||
import ./tg-ws-proxy.nix {
|
||||
inherit lib pkgs packages cfg;
|
||||
}
|
||||
))
|
||||
|
||||
(lib.mkIf cfg.tray.enable (
|
||||
import ./tray.nix {
|
||||
@@ -69,6 +75,7 @@ in
|
||||
config
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
# Shared service-layer assembly used by runtime module and docs generation.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
cfg,
|
||||
tproxyFile,
|
||||
tunFile,
|
||||
perAppTunFile,
|
||||
perAppTunChainFile,
|
||||
perAppTproxyRulesFile,
|
||||
perAppZapretRulesFile,
|
||||
ip,
|
||||
nft,
|
||||
}:
|
||||
|
||||
let
|
||||
singBoxCfg = cfg.singBox;
|
||||
perAppRoutingCfg = cfg.perAppRouting;
|
||||
globalTun = singBoxCfg.tun;
|
||||
globalTproxy = singBoxCfg.tproxy;
|
||||
perAppRoutingTun = singBoxCfg.tun.perApp;
|
||||
perAppRoutingTproxy = singBoxCfg.tproxy.perApp;
|
||||
perAppZapretCfg = cfg.zapret.perApp;
|
||||
userControlCfg = cfg.userControl;
|
||||
|
||||
builtinTags = [ "proxy" "direct" "block" ];
|
||||
outboundTags = map (ob: ob.tag) singBoxCfg.outbounds;
|
||||
invalidRoutingTargets = lib.unique (
|
||||
map (rule: rule.outbound) (
|
||||
builtins.filter (rule: !builtins.elem rule.outbound (builtinTags ++ outboundTags)) singBoxCfg.routing.rules
|
||||
)
|
||||
);
|
||||
|
||||
# Tool paths – defined once here and passed into sub-modules as needed.
|
||||
jq = "${pkgs.jq}/bin/jq";
|
||||
python3 = "${pkgs.python3}/bin/python3";
|
||||
singBox = "${pkgs.sing-box}/bin/sing-box";
|
||||
grepBin = "${pkgs.gnugrep}/bin/grep";
|
||||
awk = "${pkgs.gawk}/bin/awk";
|
||||
sleepBin = "${pkgs.coreutils}/bin/sleep";
|
||||
headBin = "${pkgs.coreutils}/bin/head";
|
||||
seqBin = "${pkgs.coreutils}/bin/seq";
|
||||
findBin = "${pkgs.findutils}/bin/find";
|
||||
|
||||
proxySuiteScriptsDir = ../../../scripts;
|
||||
parserScriptsPythonPath = proxySuiteScriptsDir;
|
||||
buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py";
|
||||
fetchSubscriptionPy = "${proxySuiteScriptsDir}/fetch-subscription.py";
|
||||
|
||||
polkit = import ./polkit.nix {
|
||||
inherit lib cfg userControlCfg;
|
||||
};
|
||||
|
||||
scripts = import ./scripts.nix {
|
||||
inherit lib pkgs singBoxCfg perAppRoutingTun;
|
||||
inherit jq python3 singBox parserScriptsPythonPath buildOutboundPy fetchSubscriptionPy;
|
||||
inherit tproxyFile tunFile perAppTunFile;
|
||||
};
|
||||
|
||||
perAppRouting = import ./per-app-routing.nix {
|
||||
inherit lib pkgs cfg singBoxCfg perAppRoutingCfg perAppRoutingTun perAppRoutingTproxy;
|
||||
perAppZapretCfg = perAppZapretCfg;
|
||||
inherit perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile;
|
||||
inherit ip nft;
|
||||
inherit awk grepBin findBin headBin seqBin sleepBin;
|
||||
};
|
||||
|
||||
control = import ./control.nix {
|
||||
inherit packages singBoxCfg perAppRoutingCfg perAppRoutingTun perAppRoutingTproxy perAppZapretCfg;
|
||||
zapretEnabled = cfg.zapret.enable;
|
||||
inherit (scripts) subscriptionTagsList;
|
||||
inherit (perAppRouting)
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
singBoxCfg
|
||||
perAppRoutingCfg
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
userControlCfg
|
||||
builtinTags
|
||||
outboundTags
|
||||
invalidRoutingTargets
|
||||
polkit
|
||||
scripts
|
||||
perAppRouting
|
||||
control
|
||||
;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
# Builds proxy-ctl from global proxy-suite state and per-app routing metadata.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
singBoxCfg,
|
||||
perAppRoutingCfg,
|
||||
perAppRoutingTun,
|
||||
@@ -13,14 +12,8 @@
|
||||
proxychainsConfigFile,
|
||||
proxychainsQuietArg,
|
||||
}:
|
||||
|
||||
let
|
||||
mkProxyCtl = import ../../../pkgs/proxy-ctl.nix {
|
||||
inherit lib pkgs;
|
||||
};
|
||||
in
|
||||
{
|
||||
proxyCtl = mkProxyCtl {
|
||||
proxyCtl = packages.mkProxyCtl {
|
||||
clashApi = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
|
||||
selection = singBoxCfg.selection;
|
||||
inherit
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
cfg,
|
||||
tproxyFile,
|
||||
tunFile,
|
||||
@@ -16,67 +17,40 @@
|
||||
}:
|
||||
|
||||
let
|
||||
singBoxCfg = cfg.singBox;
|
||||
perAppRoutingCfg = cfg.perAppRouting;
|
||||
globalTun = singBoxCfg.tun;
|
||||
globalTproxy = singBoxCfg.tproxy;
|
||||
perAppRoutingTun = singBoxCfg.tun.perApp;
|
||||
perAppRoutingTproxy = singBoxCfg.tproxy.perApp;
|
||||
perAppZapretCfg = cfg.zapret.perApp;
|
||||
userControlCfg = cfg.userControl;
|
||||
|
||||
builtinTags = [ "proxy" "direct" "block" ];
|
||||
outboundTags = map (ob: ob.tag) singBoxCfg.outbounds;
|
||||
invalidRoutingTargets = lib.unique (
|
||||
map (rule: rule.outbound) (
|
||||
builtins.filter (rule: !builtins.elem rule.outbound (builtinTags ++ outboundTags)) singBoxCfg.routing.rules
|
||||
)
|
||||
);
|
||||
|
||||
# Tool paths – defined once here and passed into sub-modules as needed.
|
||||
jq = "${pkgs.jq}/bin/jq";
|
||||
python3 = "${pkgs.python3}/bin/python3";
|
||||
singBox = "${pkgs.sing-box}/bin/sing-box";
|
||||
grepBin = "${pkgs.gnugrep}/bin/grep";
|
||||
awk = "${pkgs.gawk}/bin/awk";
|
||||
sleepBin = "${pkgs.coreutils}/bin/sleep";
|
||||
headBin = "${pkgs.coreutils}/bin/head";
|
||||
seqBin = "${pkgs.coreutils}/bin/seq";
|
||||
findBin = "${pkgs.findutils}/bin/find";
|
||||
|
||||
proxySuiteScriptsDir = ../../../scripts;
|
||||
parserScriptsPythonPath = proxySuiteScriptsDir;
|
||||
buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py";
|
||||
fetchSubscriptionPy = "${proxySuiteScriptsDir}/fetch-subscription.py";
|
||||
|
||||
polkit = import ./polkit.nix {
|
||||
inherit lib cfg userControlCfg;
|
||||
};
|
||||
|
||||
scripts = import ./scripts.nix {
|
||||
inherit lib pkgs singBoxCfg perAppRoutingTun;
|
||||
inherit jq python3 singBox parserScriptsPythonPath buildOutboundPy fetchSubscriptionPy;
|
||||
inherit tproxyFile tunFile perAppTunFile;
|
||||
};
|
||||
|
||||
perAppRouting = import ./per-app-routing.nix {
|
||||
inherit lib pkgs cfg singBoxCfg perAppRoutingCfg perAppRoutingTun perAppRoutingTproxy;
|
||||
perAppZapretCfg = perAppZapretCfg;
|
||||
inherit perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile;
|
||||
inherit ip nft;
|
||||
inherit awk grepBin findBin headBin seqBin sleepBin;
|
||||
};
|
||||
|
||||
control = import ./control.nix {
|
||||
inherit lib pkgs singBoxCfg perAppRoutingCfg perAppRoutingTun perAppRoutingTproxy perAppZapretCfg;
|
||||
zapretEnabled = cfg.zapret.enable;
|
||||
inherit (scripts) subscriptionTagsList;
|
||||
inherit (perAppRouting)
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
context = import ./context.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
perAppZapretRulesFile
|
||||
ip
|
||||
nft
|
||||
;
|
||||
};
|
||||
|
||||
inherit (context)
|
||||
singBoxCfg
|
||||
perAppRoutingCfg
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
userControlCfg
|
||||
builtinTags
|
||||
outboundTags
|
||||
invalidRoutingTargets
|
||||
polkit
|
||||
scripts
|
||||
perAppRouting
|
||||
control
|
||||
;
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [ control.proxyCtl ];
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
cfg,
|
||||
}:
|
||||
|
||||
let
|
||||
t = cfg.tgWsProxy;
|
||||
tgPkg = import ../../pkgs/tg-ws-proxy.nix { inherit pkgs; };
|
||||
tgPkg = packages.tg-ws-proxy;
|
||||
|
||||
dcArgs = lib.concatMapStrings (id: " --dc-ip=${id}:${t.dcIps.${id}}") (builtins.attrNames t.dcIps);
|
||||
startScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-start" ''
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
cfg,
|
||||
}:
|
||||
|
||||
let
|
||||
tray = cfg.tray;
|
||||
|
||||
proxyTray = import ../../pkgs/proxy-suite-tray.nix {
|
||||
inherit pkgs;
|
||||
proxyTray = packages.mkProxySuiteTray {
|
||||
pollInterval = tray.pollInterval;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
readmeDocSource = builtins.readFile ../nix/readme-doc.nix;
|
||||
trayModuleSource = builtins.readFile ../modules/proxy-suite/tray.nix;
|
||||
tgWsProxyModuleSource = builtins.readFile ../modules/proxy-suite/tg-ws-proxy.nix;
|
||||
controlModuleSource = builtins.readFile ../modules/proxy-suite/service/control.nix;
|
||||
evalProxySuite =
|
||||
modules:
|
||||
import "${nixpkgs}/nixos/lib/eval-config.nix" {
|
||||
@@ -2250,4 +2254,21 @@ in
|
||||
diff -u ${../README.md} ${generatedReadmeDoc}
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
readme-doc-source = builtins.seq
|
||||
(
|
||||
assert !(pkgs.lib.hasInfix "environment.systemPackages" readmeDocSource);
|
||||
assert !(pkgs.lib.hasInfix "packageByPattern" readmeDocSource);
|
||||
true
|
||||
)
|
||||
(pkgs.writeText "proxy-suite-readme-doc-source-check" "ok");
|
||||
|
||||
package-source = builtins.seq
|
||||
(
|
||||
assert !(pkgs.lib.hasInfix "../../pkgs/proxy-suite-tray.nix" trayModuleSource);
|
||||
assert !(pkgs.lib.hasInfix "../../pkgs/tg-ws-proxy.nix" tgWsProxyModuleSource);
|
||||
assert !(pkgs.lib.hasInfix "../../../pkgs/proxy-ctl.nix" controlModuleSource);
|
||||
true
|
||||
)
|
||||
(pkgs.writeText "proxy-suite-package-source-check" "ok");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
|
||||
singBox.outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
+28
-23
@@ -2,47 +2,52 @@
|
||||
nixpkgs,
|
||||
pkgsFor,
|
||||
proxySuiteModule,
|
||||
zapret,
|
||||
}:
|
||||
|
||||
system:
|
||||
|
||||
let
|
||||
pkgs = pkgsFor system;
|
||||
lib = pkgs.lib;
|
||||
packages = import ../pkgs/default.nix { inherit pkgs; };
|
||||
fixture = import ./readme-doc-fixture.nix;
|
||||
eval = import "${nixpkgs}/nixos/lib/eval-config.nix" {
|
||||
inherit system;
|
||||
modules = [
|
||||
proxySuiteModule
|
||||
{
|
||||
system.stateVersion = lib.trivial.release;
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
singBox.outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
fixture
|
||||
];
|
||||
};
|
||||
packageByPattern =
|
||||
packages: pattern:
|
||||
builtins.head (
|
||||
builtins.filter (
|
||||
pkg: builtins.match pattern (builtins.unsafeDiscardStringContext (toString pkg)) != null
|
||||
) packages
|
||||
);
|
||||
proxyCtl =
|
||||
packageByPattern eval.config.environment.systemPackages ".*/[^/]*proxy-ctl(-[0-9.]+)?$";
|
||||
cfg = eval.config.services.proxy-suite;
|
||||
rules = import ../modules/proxy-suite/rules.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg zapret;
|
||||
};
|
||||
configs = import ../modules/proxy-suite/config.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg rules;
|
||||
};
|
||||
nftr = import ../modules/proxy-suite/nftables.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg;
|
||||
};
|
||||
context = import ../modules/proxy-suite/service/context.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
inherit (configs) tproxyFile tunFile perAppTunFile;
|
||||
inherit (nftr) perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile ip nft;
|
||||
};
|
||||
in
|
||||
pkgs.runCommand "proxy-suite-README.md" { nativeBuildInputs = [ pkgs.python3 ]; } ''
|
||||
src=${../README.md}
|
||||
help_file="$TMPDIR/proxy-ctl-help.txt"
|
||||
export src help_file
|
||||
|
||||
${proxyCtl}/bin/proxy-ctl help > "$help_file"
|
||||
${context.control.proxyCtl}/bin/proxy-ctl help > "$help_file"
|
||||
|
||||
python <<'PY'
|
||||
from pathlib import Path
|
||||
|
||||
+15
-2
@@ -1,5 +1,18 @@
|
||||
{ pkgs }:
|
||||
let
|
||||
mkTgWsProxy = _args: import ./tg-ws-proxy.nix { inherit pkgs; };
|
||||
mkProxySuiteTray = args: import ./proxy-suite-tray.nix ({ inherit pkgs; } // args);
|
||||
mkProxyCtl = import ./proxy-ctl.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs;
|
||||
};
|
||||
in
|
||||
{
|
||||
tg-ws-proxy = import ./tg-ws-proxy.nix { inherit pkgs; };
|
||||
proxy-suite-tray = import ./proxy-suite-tray.nix { inherit pkgs; };
|
||||
inherit
|
||||
mkTgWsProxy
|
||||
mkProxySuiteTray
|
||||
mkProxyCtl
|
||||
;
|
||||
tg-ws-proxy = mkTgWsProxy { };
|
||||
proxy-suite-tray = mkProxySuiteTray { };
|
||||
}
|
||||
Reference in new issue
Block a user