refactor: move out large code blocks out of nix

This commit is contained in:
fufsob authored and FUFSoB committed 2026-10-04 11:54:04 +05:00
1 parent e8ace6523d
commit af5b3ff27a
47 files changed
+2220 -2070

No files matched your search

+2 -53
View File
@@ -1,6 +1,7 @@
{ pkgs }:
let
fillTemplate = import ../modules/proxy-suite/lib/fill-template.nix;
src = pkgs.fetchFromGitHub {
owner = "Flowseal";
repo = "tg-ws-proxy";
@@ -19,57 +20,5 @@ in
pkgs.writeShellApplication {
name = "tg-ws-proxy";
runtimeInputs = [ pythonEnv ];
text = ''
set -euo pipefail
secret=""
script_path="${src}/proxy/tg_ws_proxy.py"
args=()
while [ "$#" -gt 0 ]; do
case "$1" in
--secret-file=*)
secret=$(tr -d '\r\n' < "''${1#--secret-file=}")
shift
;;
--secret-file)
secret=$(tr -d '\r\n' < "$2")
shift 2
;;
--secret=*)
secret="''${1#--secret=}"
shift
;;
--secret)
secret="$2"
shift 2
;;
*)
args+=("$1")
shift
;;
esac
done
export PYTHONPATH="${src}"
if [ -n "$secret" ]; then
export TG_WS_PROXY_SECRET="$secret"
fi
exec python - "$script_path" "''${args[@]}" <<'PY'
import os
import runpy
import sys
script_path = sys.argv[1]
args = sys.argv[2:]
secret = os.environ.get("TG_WS_PROXY_SECRET")
if secret is not None:
args.extend(["--secret", secret])
sys.argv = ["tg_ws_proxy.py", *args]
runpy.run_path(script_path, run_name="__main__")
PY
'';
text = fillTemplate ./tg-ws-proxy.template.sh { inherit src; };
}
+51
View File
@@ -0,0 +1,51 @@
set -euo pipefail
secret=""
script_path="@src@/proxy/tg_ws_proxy.py"
args=()
while [ "$#" -gt 0 ]; do
case "$1" in
--secret-file=*)
secret=$(tr -d '\r\n' < "${1#--secret-file=}")
shift
;;
--secret-file)
secret=$(tr -d '\r\n' < "$2")
shift 2
;;
--secret=*)
secret="${1#--secret=}"
shift
;;
--secret)
secret="$2"
shift 2
;;
*)
args+=("$1")
shift
;;
esac
done
export PYTHONPATH="@src@"
if [ -n "$secret" ]; then
export TG_WS_PROXY_SECRET="$secret"
fi
exec python - "$script_path" "${args[@]}" <<'PY'
import os
import runpy
import sys
script_path = sys.argv[1]
args = sys.argv[2:]
secret = os.environ.get("TG_WS_PROXY_SECRET")
if secret is not None:
args.extend(["--secret", secret])
sys.argv = ["tg_ws_proxy.py", *args]
runpy.run_path(script_path, run_name="__main__")
PY