From f333a490e074f6ad4e0710a49acce19188b485d2 Mon Sep 17 00:00:00 2001 From: Lin Yinfeng Date: Thu, 7 Mar 2024 18:20:47 +0800 Subject: [PATCH] networking/fw-proxy: provide all_proxy env for cmdline --- nixos/modules/networking/fw-proxy/default.nix | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/nixos/modules/networking/fw-proxy/default.nix b/nixos/modules/networking/fw-proxy/default.nix index c84a21739..f044e0bf0 100644 --- a/nixos/modules/networking/fw-proxy/default.nix +++ b/nixos/modules/networking/fw-proxy/default.nix @@ -12,13 +12,13 @@ enableProxy = pkgs.writeShellApplication { name = "enable-proxy"; text = '' - ${lib.concatMapStringsSep "\n" (env: ''export ${env.name}="${env.value}"'') (lib.attrsToList cfg.environment)} + ${lib.concatMapStringsSep "\n" (env: ''export ${env.name}="${env.value}"'') (lib.attrsToList cfg.environmentCommandLine)} ''; }; disableProxy = pkgs.writeShellApplication { name = "disable-proxy"; text = '' - ${lib.concatMapStringsSep "\n" (name: ''export ${name}=""'') (lib.attrNames cfg.environment)} + ${lib.concatMapStringsSep "\n" (name: ''export ${name}=""'') (lib.attrNames cfg.environmentCommandLine)} ''; }; updateSingBoxUrl = pkgs.writeShellApplication { @@ -398,6 +398,25 @@ in no_proxy = cfg.noProxy; }; }; + environmentCommandLine = mkOption { + type = with types; attrsOf str; + description = '' + Proxy environment for command line. + ''; + default = let + proxyUrl = "http://localhost:${toString mixedPort}"; + socksProxyUrl = "socks5h://localhost:${toString mixedPort}"; + in { + HTTP_PROXY = proxyUrl; + HTTPS_PROXY = proxyUrl; + ALL_PROXY = socksProxyUrl; + http_proxy = proxyUrl; + https_proxy = proxyUrl; + all_proxy = socksProxyUrl; + NO_PROXY = cfg.noProxy; + no_proxy = cfg.noProxy; + }; + }; environmentContainter = mkOption { type = with types; attrsOf str; description = ''