about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-02-16T13·46+0100
committerEelco Dolstra <edolstra@gmail.com>2017-02-16T13·50+0100
commitcde4b609192d11dc299ea3c27d7f92735f161db1 (patch)
tree97b19b5ddce360fa68eb46036f364b716c2ea182
parentbd5388e7b22daa2d22c21578ef5735be8b8353a6 (diff)
Move netrcFile to Settings
Also get rid of Settings::processEnvironment(), it appears to be
useless.
-rw-r--r--perl/lib/Nix/Store.xs1
-rw-r--r--src/libmain/shared.cc1
-rw-r--r--src/libstore/download.cc7
-rw-r--r--src/libstore/globals.cc36
-rw-r--r--src/libstore/globals.hh6
5 files changed, 23 insertions, 28 deletions
diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs
index 6b137a13c4..f613e3df32 100644
--- a/perl/lib/Nix/Store.xs
+++ b/perl/lib/Nix/Store.xs
@@ -26,7 +26,6 @@ static ref<Store> store()
     if (!_store) {
         try {
             logger = makeDefaultLogger();
-            settings.processEnvironment();
             settings.loadConfFile();
             settings.update();
             settings.lockCPU = false;
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 56aa3db001..53fa83fe0d 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -112,7 +112,6 @@ void initNix()
     opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks());
     CRYPTO_set_locking_callback(opensslLockCallback);
 
-    settings.processEnvironment();
     settings.loadConfFile();
 
     startSignalHandlerThread();
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index d65ac7b873..d301d4409b 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -232,11 +232,8 @@ struct CurlDownloader : public Downloader
             }
 
             /* If no file exist in the specified path, curl continues to work
-             * anyway as if netrc support was disabled. */
-            Path netrcFile = settings.get("netrc-file",
-               (format("%1%/%2%") % settings.nixConfDir % "netrc").str());
-            /* Curl copies the given C string, so the following call is safe. */
-            curl_easy_setopt(req, CURLOPT_NETRC_FILE, netrcFile.c_str());
+               anyway as if netrc support was disabled. */
+            curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.c_str());
             curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 
             result.data = std::make_shared<std::string>();
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 90f83a5bbd..474288b781 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -23,6 +23,21 @@ Settings settings;
 
 Settings::Settings()
 {
+    nixPrefix = NIX_PREFIX;
+    nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
+    nixDataDir = canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR));
+    nixLogDir = canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR));
+    nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR));
+    nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR));
+    nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR));
+    nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
+    nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
+
+    // should be set with the other config options, but depends on nixLibexecDir
+#ifdef __APPLE__
+    preBuildHook = nixLibexecDir + "/nix/resolve-system-dependencies";
+#endif
+
     keepFailed = false;
     keepGoing = false;
     tryFallback = false;
@@ -57,25 +72,7 @@ Settings::Settings()
     lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
     showTrace = false;
     enableImportNative = false;
-}
-
-
-void Settings::processEnvironment()
-{
-    nixPrefix = NIX_PREFIX;
-    nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
-    nixDataDir = canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR));
-    nixLogDir = canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR));
-    nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR));
-    nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR));
-    nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR));
-    nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
-    nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
-
-    // should be set with the other config options, but depends on nixLibexecDir
-#ifdef __APPLE__
-    preBuildHook = nixLibexecDir + "/nix/resolve-system-dependencies";
-#endif
+    netrcFile = fmt("%s/%s", nixConfDir, "netrc");
 }
 
 
@@ -183,6 +180,7 @@ void Settings::update()
     _get(preBuildHook, "pre-build-hook");
     _get(keepGoing, "keep-going");
     _get(keepFailed, "keep-failed");
+    _get(netrcFile, "netrc-file");
 }
 
 
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index a423b4e5c0..0ff18f8b16 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -16,8 +16,6 @@ struct Settings {
 
     Settings();
 
-    void processEnvironment();
-
     void loadConfFile();
 
     void set(const string & name, const string & value);
@@ -193,6 +191,10 @@ struct Settings {
        build settings */
     Path preBuildHook;
 
+    /* Path to the netrc file used to obtain usernames/passwords for
+       downloads. */
+    Path netrcFile;
+
 private:
     SettingsMap settings, overrides;