about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r--third_party/nix/src/libstore/build.cc2
-rw-r--r--third_party/nix/src/libstore/gc.cc3
-rw-r--r--third_party/nix/src/libstore/globals.cc25
-rw-r--r--third_party/nix/src/libstore/globals.hh4
-rw-r--r--third_party/nix/src/libstore/local-store.hh5
-rw-r--r--third_party/nix/src/libstore/ssh.cc4
6 files changed, 24 insertions, 19 deletions
diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc
index 3dce1566535d..6e4ca99b15d0 100644
--- a/third_party/nix/src/libstore/build.cc
+++ b/third_party/nix/src/libstore/build.cc
@@ -2582,7 +2582,7 @@ void DerivationGoal::initEnv() {
   if (fixedOutput) {
     for (auto& i :
          parsedDrv->getStringsAttr("impureEnvVars").value_or(Strings())) {
-      env[i] = getEnv(i);
+      env[i] = getEnv(i).value_or("");
     }
   }
 
diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc
index 4f04e09a7555..50c52bb009bb 100644
--- a/third_party/nix/src/libstore/gc.cc
+++ b/third_party/nix/src/libstore/gc.cc
@@ -906,7 +906,8 @@ void LocalStore::collectGarbage(const GCOptions& options, GCResults& results) {
 }
 
 void LocalStore::autoGC(bool sync) {
-  static auto fakeFreeSpaceFile = getEnv("_NIX_TEST_FREE_SPACE_FILE", "");
+  static auto fakeFreeSpaceFile =
+      getEnv("_NIX_TEST_FREE_SPACE_FILE").value_or("");
 
   auto getAvail = [this]() -> uint64_t {
     if (!fakeFreeSpaceFile.empty()) {
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);
diff --git a/third_party/nix/src/libstore/globals.hh b/third_party/nix/src/libstore/globals.hh
index 54defff06bd1..29848fbb4b7a 100644
--- a/third_party/nix/src/libstore/globals.hh
+++ b/third_party/nix/src/libstore/globals.hh
@@ -61,8 +61,8 @@ class Settings : public Config {
   /* File name of the socket the daemon listens to.  */
   Path nixDaemonSocketFile;
 
-  Setting<std::string> storeUri{this, getEnv("NIX_REMOTE", "auto"), "store",
-                                "The default Nix store to use."};
+  Setting<std::string> storeUri{this, getEnv("NIX_REMOTE").value_or("auto"),
+                                "store", "The default Nix store to use."};
 
   Setting<bool> keepFailed{
       this, false, "keep-failed",
diff --git a/third_party/nix/src/libstore/local-store.hh b/third_party/nix/src/libstore/local-store.hh
index 193050e538b2..cfcfb35cc3cc 100644
--- a/third_party/nix/src/libstore/local-store.hh
+++ b/third_party/nix/src/libstore/local-store.hh
@@ -98,8 +98,9 @@ class LocalStore : public LocalFSStore {
  public:
   // Hack for build-remote.cc.
   // TODO(tazjin): remove this when we've got gRPC
-  PathSet locksHeld = absl::StrSplit(
-      getEnv("NIX_HELD_LOCKS"), absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
+  PathSet locksHeld =
+      absl::StrSplit(getEnv("NIX_HELD_LOCKS").value_or(""),
+                     absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
 
   /* Initialise the local store, upgrading the schema if
      necessary. */
diff --git a/third_party/nix/src/libstore/ssh.cc b/third_party/nix/src/libstore/ssh.cc
index 7d5fe6d10937..6043e584ddbe 100644
--- a/third_party/nix/src/libstore/ssh.cc
+++ b/third_party/nix/src/libstore/ssh.cc
@@ -22,8 +22,8 @@ SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
 
 void SSHMaster::addCommonSSHOpts(Strings& args) {
   for (auto& i :
-       absl::StrSplit(getEnv("NIX_SSHOPTS"), absl::ByAnyChar(" \t\n\r"),
-                      absl::SkipEmpty())) {
+       absl::StrSplit(getEnv("NIX_SSHOPTS").value_or(""),
+                      absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty())) {
     args.push_back(std::string(i));
   }
   if (!keyFile.empty()) {