diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-05-03 15:01:15 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-05-03 15:01:15 +0200 |
commit | 08355643ab2811256b8d78265757d9aab216b38e (patch) | |
tree | 8592f696a0cbffffdc1ecd54dcef21e0505f75e0 /src | |
parent | 782c0bff45593e7116d9b17b7de71b7ee636a807 (diff) |
nix-shell: Implement passAsFile
Diffstat (limited to 'src')
-rwxr-xr-x | src/nix-build/nix-build.cc | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index bb031d515..cd4dee326 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; @@ -407,8 +408,20 @@ int main(int argc, char ** argv) env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = tmp; env["NIX_STORE"] = store->storeDir; + 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(); @@ -418,7 +431,7 @@ 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; " |