forked from lix-project/lix
* 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 ... "; ... }
This commit is contained in:
parent
de90fdf908
commit
7974aae81c
|
@ -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)
|
static Expr primToXML(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
ostringstream out;
|
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. */
|
/* Boolean constructors. */
|
||||||
static Expr primTrue(EvalState & state, const ATermVector & args)
|
static Expr primTrue(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
|
@ -724,6 +737,7 @@ void EvalState::addPrimOps()
|
||||||
addPrimOp("dirOf", 1, primDirOf);
|
addPrimOp("dirOf", 1, primDirOf);
|
||||||
addPrimOp("toString", 1, primToString);
|
addPrimOp("toString", 1, primToString);
|
||||||
addPrimOp("__toXML", 1, primToXML);
|
addPrimOp("__toXML", 1, primToXML);
|
||||||
|
addPrimOp("__toFile", 1, primToFile);
|
||||||
addPrimOp("isNull", 1, primIsNull);
|
addPrimOp("isNull", 1, primIsNull);
|
||||||
addPrimOp("dependencyClosure", 1, primDependencyClosure);
|
addPrimOp("dependencyClosure", 1, primDependencyClosure);
|
||||||
addPrimOp("abort", 1, primAbort);
|
addPrimOp("abort", 1, primAbort);
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
derivation {
|
let {
|
||||||
name = "gc-runtime";
|
|
||||||
system = "@system@";
|
# Test inline source file definitions.
|
||||||
builder = "@shell@";
|
builder = builtins.toFile "
|
||||||
args = ["-e" "-x" ./gc-runtime.builder.sh];
|
mkdir $out
|
||||||
PATH = "@testPath@";
|
|
||||||
|
cat > $out/program <<EOF
|
||||||
|
#! $SHELL
|
||||||
|
sleep 10000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x $out/program
|
||||||
|
";
|
||||||
|
|
||||||
|
body = derivation {
|
||||||
|
name = "gc-runtime";
|
||||||
|
system = "@system@";
|
||||||
|
builder = "@shell@";
|
||||||
|
args = ["-e" "-x" builder];
|
||||||
|
PATH = "@testPath@";
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue