From 785cb3a75476033ba6eec2fef334d47d8e64388a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Nov 2019 16:06:44 +0100 Subject: refactor(tvix): getEnv(): Return std::optional 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 --- third_party/nix/src/nix-build/nix-build.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'third_party/nix/src/nix-build/nix-build.cc') diff --git a/third_party/nix/src/nix-build/nix-build.cc b/third_party/nix/src/nix-build/nix-build.cc index 30ab2a8136d2..26c308967724 100644 --- a/third_party/nix/src/nix-build/nix-build.cc +++ b/third_party/nix/src/nix-build/nix-build.cc @@ -377,9 +377,12 @@ 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 . */ - auto shell = getEnv("NIX_BUILD_SHELL", ""); + auto opt_shell = getEnv("NIX_BUILD_SHELL"); + std::string shell; - if (shell.empty()) { + if (opt_shell.has_value()) { + shell = opt_shell.value(); + } else { try { auto expr = state->parseExprFromString( "(import {}).bashInteractive", absPath(".")); @@ -427,7 +430,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").value_or(getEnv("XDG_RUNTIME_DIR").value_or("/tmp")); if (pure) { decltype(env) newEnv; -- cgit 1.4.1