proxy-suite-flake

Declarative proxy stack for NixOS, on either side of the connection: as a client that routes this host's traffic through outbounds, as a server that accepts clients on its own inbounds, or both at once. Configure it in Nix, rebuild, and it runs as systemd services. It also runs on other Linux distributions (through system-manager or home-manager) and on Android (through Nix-on-Droid): see Other hosts.

Important

This project is for study and research purposes only: learning how proxies, tunnels and traffic routing work. It comes with no warranty, and the authors are not responsible for how it is used.

Note

This project is developed with AI assistance: much of the code and documentation was written with AI tools, then reviewed and tested on real-world setups.

Bundles sing-box, XRay, AmneziaWG, zapret-discord-youtube, zapret2 and tg-ws-proxy; see their repositories for their own licenses and documentation.

Inspired by Throne (formerly NekoRay), 3x-ui and other similar projects.

Features

  • Local SOCKS5/HTTP proxy on 127.0.0.1:1080, backed by sing-box, XRay, or both
  • Global TProxy or TUN mode, on demand or at boot
  • Per-app routing: proxy-ctl apps run <profile> -- <cmd> through proxychains, a per-app TUN/TProxy, or zapret
  • Outbounds from URLs, raw JSON or subscriptions; manual or latency-based selection; per-outbound routing
  • vless (REALITY, TLS), vmess, trojan, shadowsocks, hysteria2, socks, http; TUIC, AnyTLS and NaïveProxy on sing-box, XHTTP/ECH on XRay
  • Proxy chains: any outbound or a whole subscription can connect through another (detour)
  • autoProxy: finds which exit reaches a blocked site and routes it there
  • zapret DPI bypass, including zapret2, which learns blocked sites at runtime
  • AmneziaWG 1.x–3.x tunnels from .conf, vpn://, or Nix
  • Telegram MTProto WebSocket proxy and SSH SOCKS5 tunnel
  • Cloudflare WARP from a wgcf profile, as an outbound or an AWG VPN profile
  • Server inbounds with share links, QR codes, per-user subscriptions and traffic stats
  • Proxy Suite GUI (a desktop app with a tray icon), the proxy-ctl CLI, and the proxy-tui terminal UI

Setup

inputs.proxy-suite.url = "github:FUFSoB/proxy-suite-flake";
modules = [ inputs.proxy-suite.nixosModules.default ];

Starter config:

services.proxy-suite = {
  enable = true;

  proxy = {
    enable = true;
    backend = "sing-box"; # or "xray", or "hybrid"

    # url ends up in the Nix store; use urlFile for real secrets.
    outbounds = [ { tag = "nl-vps"; url = "hy2://password@example.com:443?sni=example.com"; } ];
    subscriptions = [ { tag = "main-sub"; urlFile = "/run/secrets/sub-url"; } ];
    selection = "urltest"; # Default is "first", without any complex selector

    tproxy.enable = true;
    tun.enable = true;
  };

  perAppRouting = {
    enable = true;
    createDefaultProfiles = true;
    proxychains.enable = true;
    tun.enable = true;
    tproxy.enable = true;
    zapret.enable = true;
  };

  zapret.enable = true; # default is zapret-discord-youtube

  sshProxy = {
    enable = true;
    server = {
      user = "root";
      host = "ssh.example.com";
    };
    identityFile = "/run/secrets/proxy-suite-ssh-key";
    hostKeyFile = "/run/secrets/proxy-suite-ssh-known-hosts";
  };

  # Only one AWG, TUN or TProxy global tunnel runs at a time.
  amneziaWg = {
    enable = true;
    profiles.home.configFile = "/run/secrets/home-amneziawg.conf";
    profiles.work.vpnFile = "/run/secrets/work-amnezia.vpn";
    # An outbound tagged "de" instead: the proxy binds to its interface, which gets no routes.
    profiles.de = {
      asOutbound = "interface"; # or "userspace" (no root), or "singBox" (plain WireGuard)
      configFile = "/run/secrets/de-amneziawg.conf";
    };
  };

  # Registers with wgcf on first start. The exit is Cloudflare, but geolocated to your own country.
  warp = {
    enable = true;
    asOutbound = "singBox"; # tag is "warp"; asOutbound = "interface" runs it as an AmneziaWG profile
    # asAmneziaWg = true; # or a global profile instead: proxy-ctl awg on warp
  };

  tgWsProxy = {
    enable = true;
    secretFile = "/run/secrets/tg-ws-proxy-secret";
  };

  gui.enable = true;
};

Other hosts

The same options work outside NixOS. Pick the module for the host; everything the host cannot do fails evaluation with a message naming the option.

NixOS system-manager home-manager Nix-on-Droid
Runs as root, systemd root, systemd user, systemd --user user, proxy-suitectl
Local SOCKS/HTTP proxy, subscriptions, selection, route modes ✓ ✓ ✓ ✓
Per-app proxychains ✓ ✓ ✓ ✓
Server inbounds, share links, stats ✓ ✓ ports ≥ 1024 ports ≥ 1024
tg-ws-proxy, SSH proxy, WARP as a sing-box outbound ✓ ✓ ✓ ✓
AmneziaWG asOutbound = "userspace" ✓ ✓ ✓ ✓
Global TUN/TProxy, per-app TUN/TProxy/zapret, zapret, AmneziaWG interfaces ✓ ✓ ✗ ✗
userControl, polkit ✓ ✓ not needed not needed
GUI ✓ ✓ ✓ ✗ (proxy-ctl, proxy-tui)

Rootless hosts get the local proxy only: nothing captures the rest of the host's traffic, so point applications at 127.0.0.1:1080 (or run them through proxy-ctl apps run).

system-manager (other distributions, as root)

# with github:numtide/system-manager
modules = [ inputs.proxy-suite.systemManagerModules.default ];
  • Units, service users and the polkit rules (/etc/polkit-1/rules.d/50-proxy-suite.rules) are installed like on NixOS; the GUI's user unit goes to /etc/systemd/user. The service users come from users.users, so system-manager needs its user management.
  • The host's firewall is left alone: open the inbound ports yourself. TUN, TProxy and zapret load their own nftables tables, which needs nf_tables, nfnetlink_queue and tun in the host kernel.
  • AmneziaWG runs on its userspace implementation (amneziaWg.kernelModulePackage must stay null). DNS pushed by a VPN profile goes through resolvectl under systemd-resolved, openresolv otherwise.

home-manager (any Linux, no root)

# homeConfigurations.<name> = home-manager.lib.homeManagerConfiguration { ... }
modules = [ inputs.proxy-suite.homeManagerModules.default ];
  • Units run in the user's systemd manager: systemctl --user status proxy-suite-socks. They stop at logout unless lingering is on: loginctl enable-linger $USER.
  • State lives in $XDG_STATE_HOME/proxy-suite, runtime files in $XDG_CACHE_HOME/proxy-suite/run.

Nix-on-Droid (Android, no root)

# nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration { ... }
modules = [ inputs.proxy-suite.nixOnDroidModules.default ];
  • Android has no systemd, so nix-on-droid switch hands the units to proxy-suitectl, a small supervisor that understands the parts of systemd units proxy-suite uses (restarts, dependencies, timers, path watches). proxy-ctl talks to it for you; directly, proxy-suitectl status, proxy-suitectl restart proxy-suite-socks and proxy-suitectl journal -u 'proxy-suite-*' -f work much like systemctl and journalctl.
  • Android gives the app no boot hook. The services start on nix-on-droid switch, and, with services.proxy-suite.nixOnDroid.startWithSession (on by default), whenever a Nix-on-Droid shell opens; proxy-suitectl boot starts them by hand.
  • Android stops background apps: acquire Nix-on-Droid's wake lock from its notification and exempt the app from battery optimisation, or the services die with the terminal.
  • Inbounds are reachable from the local network on ports from 1024 up; zapret is not available (on Android it needs a VPN app).
  • An AmneziaWG userspace outbound resolves an Endpoint hostname through the system resolver; give it as an IP address where that resolver is itself blocked.

Options

See the options reference, one page per option group. Regenerate it and the help below with nix run .#update-docs.

proxy-ctl help

Usage: proxy-ctl <group> [verb] [args]
A group without a verb shows its status or list.
Secrets and changes need root, or the userControl group.

  status [--json]                        services and routing mode (--tray: deprecated key=value lines)
  restart                                restart active services
  logs [unit]                            follow logs (default: every proxy-suite unit)
  where <domain>                         how this host is routed right now

  proxy [status|on|off]                  local proxy backend
  proxy outbounds [list]                 outbounds, where each came from, and the pick
  proxy outbounds add <tag> <url|json|-> [--detour <tag>]
                                         add an outbound at runtime: a URL, or sing-box/XRay JSON (-: stdin),
                                         chained through another outbound with --detour
  proxy outbounds rm <tag>               remove a runtime outbound
  proxy outbounds test [tag...] [--ping] [--delay] [--download]
                                         TCP ping, real delay, download speed (default: ping, delay)
  proxy outbounds link <tag> [--qr|--json|--config]
                                         its URL, QR code, backend JSON, or a client config for it
  proxy pin [tag]                        always use this outbound (no tag: pick from a menu)
  proxy unpin                            let the configured selection pick again
  proxy mode [default|whitelist|blacklist|all-proxy|all-bypass]
                                         show or override the routing mode
  proxy subs [list|update]               subscription caches; update refetches them
  proxy subs add <tag> <url>             add a subscription at runtime
  proxy subs rm <tag>                    remove a runtime subscription
  proxy subs link <tag> [--qr]           its URL
  proxy config [--raw]                   client config to import elsewhere; --raw: as running
  proxy tun [status|on|off]              global TUN mode
  proxy tproxy [status|on|off]           global TProxy mode
  proxy auto [list]                      what autoProxy routed, and via which exit
  proxy auto probe <domain>[/path] [--json] [--keep-going] [--exits a,b | --via tag]
                                         find an exit that reaches a domain
  proxy auto learn <domain>              probe now and route it if an exit works
  proxy auto queue [count]               destinations waiting to be probed

  zapret [status|on|off]                 DPI bypass
  zapret auto [list]                     hosts zapret2 learned as blocked
  zapret auto add|forget|exclude <domain>
                                         pin, forget, or never learn a host
  zapret auto unpin|include <domain>     undo add, or undo exclude
  zapret auto clear                      forget learned hosts and strategies
  zapret cutoff [status]                 networks this line cuts at 16 KB, and their names
  zapret cutoff probe                    probe this line again now

  awg [list]                             AmneziaWG profiles and their state
  awg on <profile> | off [profile] | restart [profile]

  ssh [status|on|off]                    SSH SOCKS5 tunnel
  warp [status|on|off]                   WARP tunnel behind the warp outbound
  tg [status|on|off]                     Telegram WebSocket proxy

  apps [list]                            per-app routing profiles
  apps run <profile> -- <cmd> [args]     run a command through a profile

  inbounds [list]                        server inbounds
  inbounds link <tag> [user] [--qr|--json]
                                         client share link, or the client's outbound JSON
  inbounds link <tag> --server-json      the server's inbound JSON
  inbounds sub [user] [--qr]             subscription users, or one user's URL
  inbounds stats [days] [--by user|inbound|outbound]
                                         traffic per user, listener or exit
  inbounds online                        who is connected now, and when the rest were last seen
S
Description
Fork of FUFSoB/proxy-suite-flake with a native Windows port (windows branch)
Readme
8.4 MiB
1 Stars 1 Watchers 0 Forks
Languages
Python 48.1%
Nix 44.8%
Shell 4.7%
Lua 1.2%
jq 1.1%