diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12 23:05:01 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12 23:05:01 +0000 |
commit | a3e6415ba8cf1b8d2a1db40c06997d997eac8afc (patch) | |
tree | 16e43edf9a785101b562ee3bfa6cbaeb600fc22a /src/libexpr | |
parent | b438d37558eab56a2927771013c9080675381ba8 (diff) |
* New primop builtins.filterSource, which can be used to filter files
from a source directory. All files for which a predicate function
returns true are copied to the store. Typical example is to leave
out the .svn directory:
stdenv.mkDerivation {
...
src = builtins.filterSource
(path: baseNameOf (toString path) != ".svn")
./source-dir;
# as opposed to
# src = ./source-dir;
}
This is important because the .svn directory influences the hash in
a rather unpredictable and variable way.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index fcf035450..84d9f5a13 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -3,6 +3,7 @@ #include "globals.hh" #include "store-api.hh" #include "util.hh" +#include "archive.hh" #include "expr-to-xml.hh" #include "nixexpr-ast.hh" @@ -726,6 +727,42 @@ static Expr primLessThan(EvalState & state, const ATermVector & args) } +struct FilterFromExpr : PathFilter +{ + EvalState & state; + Expr filter; + + FilterFromExpr(EvalState & state, Expr filter) + : state(state), filter(filter) + { + } + + bool operator () (const Path & path) + { + printMsg(lvlError, format("filter %1%") % path); + Expr call = makeCall(filter, makePath(toATerm(path))); + return evalBool(state, call); + } +}; + + +static Expr primFilterSource(EvalState & state, const ATermVector & args) +{ + PathSet context; + Path path = coerceToPath(state, args[1], context); + if (!context.empty()) + throw EvalError(format("string `%1%' cannot refer to other paths") % path); + + FilterFromExpr filter(state, args[0]); + + Path dstPath = readOnlyMode + ? computeStorePathForPath(path, false, false, "", filter).first + : store->addToStore(path, false, false, "", filter); + + return makeStr(dstPath, singleton<PathSet>(dstPath)); +} + + void EvalState::addPrimOps() { addPrimOp("builtins", 0, primBuiltins); @@ -762,6 +799,7 @@ void EvalState::addPrimOps() addPrimOp("__add", 2, primAdd); addPrimOp("__lessThan", 2, primLessThan); addPrimOp("__toFile", 2, primToFile); + addPrimOp("__filterSource", 2, primFilterSource); } |