about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-22T15·06+0100
committerglittershark <grfn@gws.fyi>2020-09-01T02·21+0000
commit785cb3a75476033ba6eec2fef334d47d8e64388a (patch)
tree676d53868e29e0ab28443b9d13019c54754012f7 /third_party/nix/src/libstore
parentc5f3b12f0484cd1a5152b6c64a336e9852d7c484 (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')
-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 3dce156653..6e4ca99b15 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 4f04e09a75..50c52bb009 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 34f5d4605b..6babb4589f 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 54defff06b..29848fbb4b 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 193050e538..cfcfb35cc3 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 7d5fe6d109..6043e584dd 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()) {