From d3bff699aac0ff940e7e5551e39b53e62e780281 Mon Sep 17 00:00:00 2001 From: ramboman Date: Fri, 23 Feb 2024 01:05:25 -0500 Subject: [PATCH 1/2] `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 39c04069be6..687c072e0d1 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; } From bca737dcad2401b81d60f6ecf3f163b9346b5556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Fri, 23 Feb 2024 10:28:37 +0100 Subject: [PATCH 2/2] c++-ize the proxy detection code Just for consistency with the rest --- src/nix/main.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/nix/main.cc b/src/nix/main.cc index 687c072e0d1..5af5f2e4174 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -23,7 +23,6 @@ #include #include #include -#include #include @@ -35,7 +34,7 @@ namespace nix { static bool haveProxyEnvironmentVariables() { - static const char * const proxyVariables[] = { + static const std::vector proxyVariables = { "http_proxy", "https_proxy", "ftp_proxy", @@ -44,7 +43,7 @@ static bool haveProxyEnvironmentVariables() "FTP_PROXY" }; for (auto & proxyVariable: proxyVariables) { - if (std::getenv(proxyVariable)) { + if (getEnv(proxyVariable).has_value()) { return true; } }