aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index be78bca02..283f99a48 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1838,6 +1838,45 @@ static RegisterPrimOp primop_readDir({
.fun = prim_readDir,
});
+/* Extend single element string context with another output. */
+static void prim_outputOf(EvalState & state, const PosIdx pos, Value * * args, Value & v)
+{
+ SingleDerivedPath drvPath = state.coerceToSingleDerivedPath(pos, *args[0], "while evaluating the first argument to builtins.outputOf");
+
+ std::string_view outputName = state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument to builtins.outputOf");
+
+ state.mkSingleDerivedPathString(
+ SingleDerivedPath::Built {
+ .drvPath = make_ref<SingleDerivedPath>(drvPath),
+ .output = std::string { outputName },
+ },
+ v);
+}
+
+static RegisterPrimOp primop_outputOf({
+ .name = "__outputOf",
+ .args = {"derivation-reference", "output-name"},
+ .doc = R"(
+ Return the output path of a derivation, literally or using a placeholder if needed.
+
+ If the derivation has a statically-known output path (i.e. the derivation output is input-addressed, or fixed content-addresed), the output path will just be returned.
+ But if the derivation is content-addressed or if the derivation is itself not-statically produced (i.e. is the output of another derivation), a placeholder will be returned instead.
+
+ *`derivation reference`* must be a string that may contain a regular store path to a derivation, or may be a placeholder reference. If the derivation is produced by a derivation, you must explicitly select `drv.outPath`.
+ This primop can be chained arbitrarily deeply.
+ For instance,
+ ```nix
+ builtins.outputOf
+ (builtins.outputOf myDrv "out)
+ "out"
+ ```
+ will return a placeholder for the output of the output of `myDrv`.
+
+ This primop corresponds to the `^` sigil for derivable paths, e.g. as part of installable syntax on the command line.
+ )",
+ .fun = prim_outputOf,
+ .experimentalFeature = Xp::DynamicDerivations,
+});
/*************************************************************
* Creating files