From d3bff699aac0ff940e7e5551e39b53e62e780281 Mon Sep 17 00:00:00 2001 From: ramboman Date: Fri, 23 Feb 2024 01:05:25 -0500 Subject: [PATCH] `nix`: Fix `haveInternet` to check for proxy --- src/nix/main.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/nix/main.cc b/src/nix/main.cc index 39c04069b..687c072e0 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -32,6 +33,24 @@ void chrootHelper(int argc, char * * argv); namespace nix { +static bool haveProxyEnvironmentVariables() +{ + static const char * const proxyVariables[] = { + "http_proxy", + "https_proxy", + "ftp_proxy", + "HTTP_PROXY", + "HTTPS_PROXY", + "FTP_PROXY" + }; + for (auto & proxyVariable: proxyVariables) { + if (std::getenv(proxyVariable)) { + return true; + } + } + return false; +} + /* Check if we have a non-loopback/link-local network interface. */ static bool haveInternet() { @@ -55,6 +74,8 @@ static bool haveInternet() } } + if (haveProxyEnvironmentVariables()) return true; + return false; }