about summary refs log tree commit diff
path: root/src/nix-build/nix-build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-build/nix-build.cc')
-rwxr-xr-xsrc/nix-build/nix-build.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 065447684aaf..7167e96f11d3 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -15,6 +15,7 @@
 #include "shared.hh"
 
 using namespace nix;
+using namespace std::string_literals;
 
 extern char * * environ;
 
@@ -325,7 +326,7 @@ int main(int argc, char ** argv)
         if (packages) {
             instArgs.push_back("--expr");
             std::ostringstream joined;
-            joined << "with import <nixpkgs> { }; runCommand \"shell\" { buildInputs = [ ";
+            joined << "with import <nixpkgs> { }; (pkgs.runCommandCC or pkgs.runCommand) \"shell\" { buildInputs = [ ";
             for (const auto & i : exprs)
                 joined << '(' << i << ") ";
             joined << "]; } \"\"";
@@ -408,8 +409,20 @@ int main(int argc, char ** argv)
                 env["NIX_STORE"] = store->storeDir;
                 env["NIX_BUILD_CORES"] = settings.buildCores;
 
+                auto passAsFile = tokenizeString<StringSet>(get(drv.env, "passAsFile", ""));
+
+                bool keepTmp = false;
+                int fileNr = 0;
+
                 for (auto & var : drv.env)
-                    env[var.first] = var.second;
+                    if (passAsFile.count(var.first)) {
+                        keepTmp = true;
+                        string fn = ".attr-" + std::to_string(fileNr++);
+                        Path p = (Path) tmpDir + "/" + fn;
+                        writeFile(p, var.second);
+                        env[var.first + "Path"] = p;
+                    } else
+                        env[var.first] = var.second;
 
                 restoreAffinity();
 
@@ -419,14 +432,14 @@ int main(int argc, char ** argv)
                 // the current $PATH directories.
                 auto rcfile = (Path) tmpDir + "/rc";
                 writeFile(rcfile, fmt(
-                        "rm -rf '%1%'; "
+                        (keepTmp ? "" : "rm -rf '%1%'; "s) +
                         "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc; "
                         "%2%"
                         "dontAddDisableDepTrack=1; "
                         "[ -e $stdenv/setup ] && source $stdenv/setup; "
                         "%3%"
                         "set +e; "
-                        "[ -n \"$PS1\" ] && PS1=\"\\n\\[\\033[1;32m\\][nix-shell:\\w]$\\[\\033[0m\\] \"; "
+                        R"s([ -n "$PS1" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s"
                         "if [ \"$(type -t runHook)\" = function ]; then runHook shellHook; fi; "
                         "unset NIX_ENFORCE_PURITY; "
                         "unset NIX_INDENT_MAKE; "