refactor(tvix): getEnv(): Return std::optional
This allows distinguishing between an empty value and no value.
Patch ported from upstream at
ba87b08f85
Change-Id: I061cc8e16b1a7a0341adfc3b0edca1c0c51d5c97
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1884
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
parent
c5f3b12f04
commit
785cb3a754
17 changed files with 66 additions and 66 deletions
2
third_party/nix/src/libstore/build.cc
vendored
2
third_party/nix/src/libstore/build.cc
vendored
|
|
@ -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("");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
3
third_party/nix/src/libstore/gc.cc
vendored
3
third_party/nix/src/libstore/gc.cc
vendored
|
|
@ -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()) {
|
||||
|
|
|
|||
25
third_party/nix/src/libstore/globals.cc
vendored
25
third_party/nix/src/libstore/globals.cc
vendored
|
|
@ -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);
|
||||
|
|
|
|||
4
third_party/nix/src/libstore/globals.hh
vendored
4
third_party/nix/src/libstore/globals.hh
vendored
|
|
@ -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",
|
||||
|
|
|
|||
5
third_party/nix/src/libstore/local-store.hh
vendored
5
third_party/nix/src/libstore/local-store.hh
vendored
|
|
@ -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. */
|
||||
|
|
|
|||
4
third_party/nix/src/libstore/ssh.cc
vendored
4
third_party/nix/src/libstore/ssh.cc
vendored
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue