diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-11-22T15·06+0100 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-09-01T02·21+0000 |
commit | 785cb3a75476033ba6eec2fef334d47d8e64388a (patch) | |
tree | 676d53868e29e0ab28443b9d13019c54754012f7 /third_party/nix/src/libstore/globals.cc | |
parent | c5f3b12f0484cd1a5152b6c64a336e9852d7c484 (diff) |
refactor(tvix): getEnv(): Return std::optional r/1756
This allows distinguishing between an empty value and no value. Patch ported from upstream at https://github.com/NixOS/nix/commit/ba87b08f8529e4d9f8c58d8c625152058ceadb75 Change-Id: I061cc8e16b1a7a0341adfc3b0edca1c0c51d5c97 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1884 Tested-by: BuildkiteCI Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'third_party/nix/src/libstore/globals.cc')
-rw-r--r-- | third_party/nix/src/libstore/globals.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/third_party/nix/src/libstore/globals.cc b/third_party/nix/src/libstore/globals.cc index 34f5d4605bf5..6babb4589fa0 100644 --- a/third_party/nix/src/libstore/globals.cc +++ b/third_party/nix/src/libstore/globals.cc @@ -31,19 +31,22 @@ static GlobalConfig::Register r1(&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))), + getEnv("NIX_STORE_DIR") + .value_or(getEnv("NIX_STORE").value_or(NIX_STORE_DIR)))), + nixDataDir(canonPath(getEnv("NIX_DATA_DIR").value_or(NIX_DATA_DIR))), + nixLogDir(canonPath(getEnv("NIX_LOG_DIR").value_or(NIX_LOG_DIR))), + nixStateDir(canonPath(getEnv("NIX_STATE_DIR").value_or(NIX_STATE_DIR))), + nixConfDir(canonPath(getEnv("NIX_CONF_DIR").value_or(NIX_CONF_DIR))), + nixLibexecDir( + canonPath(getEnv("NIX_LIBEXEC_DIR").value_or(NIX_LIBEXEC_DIR))), + nixBinDir(canonPath(getEnv("NIX_BIN_DIR").value_or(NIX_BIN_DIR))), nixManDir(canonPath(NIX_MAN_DIR)), nixDaemonSocketFile(canonPath(nixStateDir + DEFAULT_SOCKET_PATH)) { buildUsersGroup = getuid() == 0 ? "nixbld" : ""; - lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1"; + lockCPU = getEnv("NIX_AFFINITY_HACK").value_or("1") == "1"; - caFile = getEnv("NIX_SSL_CERT_FILE", getEnv("SSL_CERT_FILE", "")); + caFile = getEnv("NIX_SSL_CERT_FILE") + .value_or(getEnv("SSL_CERT_FILE").value_or("")); if (caFile.empty()) { for (auto& fn : {"/etc/ssl/certs/ca-certificates.crt", @@ -58,9 +61,9 @@ Settings::Settings() /* Backwards compatibility. */ // TODO(tazjin): still? auto s = getEnv("NIX_REMOTE_SYSTEMS"); - if (!s.empty()) { + if (s) { Strings ss; - for (auto p : absl::StrSplit(s, absl::ByChar(':'), absl::SkipEmpty())) { + for (auto p : absl::StrSplit(*s, absl::ByChar(':'), absl::SkipEmpty())) { ss.push_back(absl::StrCat("@", p)); } builders = concatStringsSep(" ", ss); |