aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-09-01 12:07:31 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-09-01 12:07:31 +0000
commit7974aae81ced67b2aee0b537a37d813f6c67a1ec (patch)
treea3b48ffca70701f967d43e1e25d3cf6772754311 /src/libexpr/primops.cc
parentde90fdf908f2504e1a89a5d4660552cbcc1a15d5 (diff)
* New primop: builtins.toFile, which writes a string into the store
and returns its path. This can be used to (for instance) write builders inside a Nix expression, e.g., stdenv.mkDerivation { builder = " source $stdenv/setup ... "; ... }
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 8a513c521..5dfe90a8f 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -467,6 +467,9 @@ static Expr primToString(EvalState & state, const ATermVector & args)
}
+/* Convert the argument (which can be any Nix expression) to an XML
+ representation returned in a string. Not all Nix expressions can
+ be sensibly or completely represented (e.g., functions). */
static Expr primToXML(EvalState & state, const ATermVector & args)
{
ostringstream out;
@@ -475,6 +478,16 @@ static Expr primToXML(EvalState & state, const ATermVector & args)
}
+/* Store a string in the Nix store as a source file that can be used
+ as an input by derivations. */
+static Expr primToFile(EvalState & state, const ATermVector & args)
+{
+ string s = evalString(state, args[0]);
+ Path storePath = addTextToStore("", s, PathSet());
+ return makePath(toATerm(storePath));
+}
+
+
/* Boolean constructors. */
static Expr primTrue(EvalState & state, const ATermVector & args)
{
@@ -724,6 +737,7 @@ void EvalState::addPrimOps()
addPrimOp("dirOf", 1, primDirOf);
addPrimOp("toString", 1, primToString);
addPrimOp("__toXML", 1, primToXML);
+ addPrimOp("__toFile", 1, primToFile);
addPrimOp("isNull", 1, primIsNull);
addPrimOp("dependencyClosure", 1, primDependencyClosure);
addPrimOp("abort", 1, primAbort);