aboutsummaryrefslogtreecommitdiff
path: root/src/nix-build
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-22 16:06:44 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-22 16:18:13 +0100
commitba87b08f8529e4d9f8c58d8c625152058ceadb75 (patch)
treec78196cbeb52273c3d5b99ff8dee314108940b9a /src/nix-build
parentfd900c45b5ff9c6dc7f3ec814eca4ad603720899 (diff)
getEnv(): Return std::optional
This allows distinguishing between an empty value and no value.
Diffstat (limited to 'src/nix-build')
-rwxr-xr-xsrc/nix-build/nix-build.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 1c5d71681..c506f9b0a 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -344,9 +344,9 @@ static void _main(int argc, char * * argv)
/* Figure out what bash shell to use. If $NIX_BUILD_SHELL
is not set, then build bashInteractive from
<nixpkgs>. */
- auto shell = getEnv("NIX_BUILD_SHELL", "");
+ auto shell = getEnv("NIX_BUILD_SHELL");
- if (shell == "") {
+ if (!shell) {
try {
auto expr = state->parseExprFromString("(import <nixpkgs> {}).bashInteractive", absPath("."));
@@ -382,7 +382,8 @@ static void _main(int argc, char * * argv)
// Set the environment.
auto env = getEnv();
- auto tmp = getEnv("TMPDIR", getEnv("XDG_RUNTIME_DIR", "/tmp"));
+ auto tmp = getEnv("TMPDIR");
+ if (!tmp) tmp = getEnv("XDG_RUNTIME_DIR").value_or("/tmp");
if (pure) {
decltype(env) newEnv;
@@ -394,7 +395,7 @@ static void _main(int argc, char * * argv)
env["__ETC_PROFILE_SOURCED"] = "1";
}
- env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = tmp;
+ env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = *tmp;
env["NIX_STORE"] = store->storeDir;
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
@@ -439,8 +440,8 @@ static void _main(int argc, char * * argv)
(Path) tmpDir,
(pure ? "" : "p=$PATH; "),
(pure ? "" : "PATH=$PATH:$p; unset p; "),
- dirOf(shell),
- shell,
+ dirOf(*shell),
+ *shell,
(getenv("TZ") ? (string("export TZ='") + getenv("TZ") + "'; ") : ""),
envCommand));
@@ -460,9 +461,9 @@ static void _main(int argc, char * * argv)
restoreSignals();
- execvp(shell.c_str(), argPtrs.data());
+ execvp(shell->c_str(), argPtrs.data());
- throw SysError("executing shell '%s'", shell);
+ throw SysError("executing shell '%s'", *shell);
}
else {