about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-02-17T13·42+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-02-17T13·42+0100
commita70d275f3d25f6e1eb1b6d528ee07ecd7265ada5 (patch)
treea103bd4348be410ec66dbde0551ec3ad5d442a74 /src/libstore
parent29e1ff675b6b8f1ba2cdcde599888ec3eebce9af (diff)
Allow passing attributes via files instead of environment variables
Closes #473.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 4841c9373ede..0b1985828b52 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1646,14 +1646,26 @@ void DerivationGoal::startBuilder()
     /* The maximum number of cores to utilize for parallel building. */
     env["NIX_BUILD_CORES"] = (format("%d") % settings.buildCores).str();
 
-    /* Add all bindings specified in the derivation. */
-    foreach (StringPairs::iterator, i, drv.env)
-        env[i->first] = i->second;
-
     /* Create a temporary directory where the build will take
        place. */
     tmpDir = createTempDir("", "nix-build-" + storePathToName(drvPath), false, false, 0700);
 
+    /* Add all bindings specified in the derivation via the
+       environments, except those listed in the passAsFile
+       attribute. Those are passed as file names pointing to
+       temporary files containing the contents. */
+    StringSet passAsFile = tokenizeString<StringSet>(get(drv.env, "passAsFile"));
+    int fileNr = 0;
+    for (auto & i : drv.env) {
+        if (passAsFile.find(i.first) == passAsFile.end()) {
+            env[i.first] = i.second;
+        } else {
+            Path p = tmpDir + "/.attr-" + int2String(fileNr++);
+            writeFile(p, i.second);
+            env[i.first] = p;
+        }
+    }
+
     /* For convenience, set an environment pointing to the top build
        directory. */
     env["NIX_BUILD_TOP"] = tmpDir;