Move netrcFile to Settings

Also get rid of Settings::processEnvironment(), it appears to be
useless.
This commit is contained in:
Eelco Dolstra 2017-02-16 14:46:36 +01:00
parent bd5388e7b2
commit cde4b60919
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 23 additions and 28 deletions

View file

@ -26,7 +26,6 @@ static ref<Store> store()
if (!_store) { if (!_store) {
try { try {
logger = makeDefaultLogger(); logger = makeDefaultLogger();
settings.processEnvironment();
settings.loadConfFile(); settings.loadConfFile();
settings.update(); settings.update();
settings.lockCPU = false; settings.lockCPU = false;

View file

@ -112,7 +112,6 @@ void initNix()
opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks()); opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks());
CRYPTO_set_locking_callback(opensslLockCallback); CRYPTO_set_locking_callback(opensslLockCallback);
settings.processEnvironment();
settings.loadConfFile(); settings.loadConfFile();
startSignalHandlerThread(); startSignalHandlerThread();

View file

@ -232,11 +232,8 @@ struct CurlDownloader : public Downloader
} }
/* If no file exist in the specified path, curl continues to work /* If no file exist in the specified path, curl continues to work
* anyway as if netrc support was disabled. */ anyway as if netrc support was disabled. */
Path netrcFile = settings.get("netrc-file", curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.c_str());
(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());
curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
result.data = std::make_shared<std::string>(); result.data = std::make_shared<std::string>();

View file

@ -23,6 +23,21 @@ Settings settings;
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; keepFailed = false;
keepGoing = false; keepGoing = false;
tryFallback = false; tryFallback = false;
@ -57,25 +72,7 @@ Settings::Settings()
lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1"; lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
showTrace = false; showTrace = false;
enableImportNative = false; enableImportNative = false;
} netrcFile = fmt("%s/%s", nixConfDir, "netrc");
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
} }
@ -183,6 +180,7 @@ void Settings::update()
_get(preBuildHook, "pre-build-hook"); _get(preBuildHook, "pre-build-hook");
_get(keepGoing, "keep-going"); _get(keepGoing, "keep-going");
_get(keepFailed, "keep-failed"); _get(keepFailed, "keep-failed");
_get(netrcFile, "netrc-file");
} }

View file

@ -16,8 +16,6 @@ struct Settings {
Settings(); Settings();
void processEnvironment();
void loadConfFile(); void loadConfFile();
void set(const string & name, const string & value); void set(const string & name, const string & value);
@ -193,6 +191,10 @@ struct Settings {
build settings */ build settings */
Path preBuildHook; Path preBuildHook;
/* Path to the netrc file used to obtain usernames/passwords for
downloads. */
Path netrcFile;
private: private:
SettingsMap settings, overrides; SettingsMap settings, overrides;