diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-03-28T20·58+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-03-28T20·58+0000 |
commit | f958bcdf1f9f66759a2512e4b7c0b0ba5647960a (patch) | |
tree | 0aea538fffa1e6d24c8e9ac320d4ce996c0c3c5c /src/libexpr/primops.cc | |
parent | db3e644c1ce7d856dbaca7718fa0af8231c486d2 (diff) |
* Added an operator `~' to select paths within a derivation. E.g.,
{stdenv, bash}: derivation { builder = bash ~ /bin/sh; args = ["-e" "-x" ./builder.sh]; ... } Here the attribute `builder' will evaluate to, e.g., `/nix/store/1234abcd...-bash-2.0.1/bin/sh'.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6c2bb33e461f..5aefa5b411b0 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -85,6 +85,7 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne, string s; ATermList es; int n; + Expr e1, e2; if (atMatch(m, e) >> "Str" >> s) ss.push_back(s); else if (atMatch(m, e) >> "Uri" >> s) ss.push_back(s); @@ -128,6 +129,18 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne, } else if (atMatch(m, e) >> "Null") ss.push_back(""); + + else if (atMatch(m, e) >> "SubPath" >> e1 >> e2) { + Strings ss2; + processBinding(state, evalExpr(state, e1), ne, ss2); + if (ss2.size() != 1) + throw Error("left-hand side of `~' operator cannot be a list"); + e2 = evalExpr(state, e2); + if (!(atMatch(m, e2) >> "Str" >> s || + (atMatch(m, e2) >> "Path" >> s))) + throw Error("right-hand side of `~' operator must be a path or string"); + ss.push_back(canonPath(ss2.front() + "/" + s)); + } else throw badTerm("invalid derivation binding", e); } |