diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/primops.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index f8f893d69683..84c4bbb883ce 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1107,6 +1107,30 @@ static void prim_unsafeDiscardOutputDependency(EvalState & state, Value * * args } +static void prim_hash(EvalState & state, Value * * args, Value & v) +{ + PathSet context; + + string type = state.forceStringNoCtx(*args[0]); + string s = state.forceStringNoCtx(*args[1]); + + HashType ht; + if (type == "md5"){ + ht = htMD5; + } else if (type == "sha256"){ + ht = htSHA256; + } else { + throw Error(format("bad hash type `%1%'") % type); + } + + Hash h = hashString(ht, s); + + string hash = printHash(h); + + mkString(v, hash, context); +}; + + /************************************************************* * Versions *************************************************************/ @@ -1235,6 +1259,8 @@ void EvalState::createBaseEnv() addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext); addPrimOp("__unsafeDiscardOutputDependency", 1, prim_unsafeDiscardOutputDependency); + addPrimOp("__hash", 2, prim_hash); + // Versions addPrimOp("__parseDrvName", 1, prim_parseDrvName); addPrimOp("__compareVersions", 2, prim_compareVersions); |