{ lib, pkgs, }: { # NAME -> value, exported into proxy-ctl and both front ends. The module builds it # (modules/proxy-suite/service/control.nix); proxy_ctl.py reads every name with env(). env, guiRefreshInterval ? 3, # These four are also passed as derivations: the checks read the files' contents through # passthru.proxySuiteCheck, which toString in env would lose. subscriptionTagsFile, perAppRoutingProfilesFile, proxychainsConfigFile, amneziaWgProfileNamesFile, }: let # Not writePython3Bin: its flake8 pass would gate the build on style. unwrapped = pkgs.writeScriptBin "proxy-ctl" ( "#!${pkgs.python3}/bin/python3\n" + builtins.readFile ./proxy-ctl/proxy_ctl.py ); wrapperEnv = env; envFlags = lib.concatStringsSep " " ( lib.mapAttrsToList (name: value: "--set ${name} ${lib.escapeShellArg value}") wrapperEnv ); # The modules both front-ends import: proxy_ctl for reads, proxy_model for the tabs and the tray menu. # proxy_export: what `proxy-ctl proxy config` imports. pythonModules = pkgs.runCommand "proxy-suite-python-modules" { } '' install -Dm644 ${./proxy-ctl/proxy_ctl.py} "$out/proxy_ctl.py" install -Dm644 ${./proxy-ctl/proxy_model.py} "$out/proxy_model.py" install -Dm644 ${./proxy-ctl/proxy_export.py} "$out/proxy_export.py" ''; # A separate package: the Textual closure stays off hosts that don't enable it. # It imports proxy_ctl for reads and runs proxy-ctl for every change. tui = pkgs.symlinkJoin { name = "proxy-tui"; paths = [ (pkgs.writeScriptBin "proxy-tui" ( "#!${pkgs.python3.withPackages (ps: [ ps.textual ])}/bin/python3\n" + builtins.readFile ./proxy-ctl/proxy_tui.py )) ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' # /run/wrappers/bin first: the store's sudo, earlier on a PATH, refuses to run without setuid. wrapProgram "$out/bin/proxy-tui" \ --prefix PYTHONPATH : ${pythonModules} \ --prefix PATH : "${ lib.makeBinPath [ proxyCtl pkgs.systemd ] }" \ --prefix PATH : /run/wrappers/bin ${envFlags} ''; }; guiPython = pkgs.python3.withPackages (ps: [ ps.pygobject3 ]); # Proxy Suite GUI: a GTK4/libadwaita window over the same tabs as the TUI, with a tray icon. # Separate for the same reason as the TUI: GTK stays off hosts that don't enable it. gui = pkgs.stdenv.mkDerivation { pname = "proxy-suite-gui"; version = "0.2.0"; dontUnpack = true; nativeBuildInputs = [ pkgs.wrapGAppsHook4 pkgs.gobject-introspection pkgs.makeWrapper guiPython ]; buildInputs = [ pkgs.gtk4 pkgs.libadwaita pkgs.adwaita-icon-theme guiPython ]; # A Python script: the wrapper is made by hand below, with the GApps arguments. dontWrapGApps = true; installPhase = '' runHook preInstall install -Dm644 ${./proxy-ctl/proxy_gui.py} "$out/lib/proxy-suite-gui/proxy_gui.py" install -Dm644 ${./proxy-ctl/proxy_sni.py} "$out/lib/proxy-suite-gui/proxy_sni.py" # Tray icons in one flat directory (the tray's IconThemePath), and in hicolor for everything else. icons="$out/share/proxy-suite-gui/icons" python3 ${./proxy-ctl/icons/badges.py} ${./proxy-ctl/icons} "$icons" install -Dm644 ${./proxy-ctl/icons/io.github.FUFSoB.ProxySuite.svg} "$icons/io.github.FUFSoB.ProxySuite.svg" for icon in "$icons"/*.svg; do case "$icon" in *-symbolic.svg) install -Dm644 "$icon" "$out/share/icons/hicolor/symbolic/apps/''${icon##*/}" ;; *) install -Dm644 "$icon" "$out/share/icons/hicolor/scalable/apps/''${icon##*/}" ;; esac done mkdir -p "$out/share/applications" "$out/share/systemd/user" cat > "$out/share/applications/io.github.FUFSoB.ProxySuite.desktop" < "$out/share/systemd/user/proxy-suite-gui.service" <