Skip to content

Commit

Permalink
networking/fw-proxy: provide all_proxy env for cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
linyinfeng committed Mar 7, 2024
1 parent 61f6b4e commit f333a49
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nixos/modules/networking/fw-proxy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = ''
Expand Down

0 comments on commit f333a49

Please sign in to comment.