query
On this page

addDrvOutputDependencies

builtins.addDrvOutputDependencies

Primop
Docs pulled from | This Revision | about 12 hours ago


Nix manual

Takes 1 arguments

s

Create a copy of the given string where a single constant string context element is turned into a derivation deep string context element.

The store path that is the constant string context element should point to a valid derivation, and end in .drv.

The original string context element must not be empty or have multiple elements, and it must not have any other type of element other than a constant or derivation deep element. The latter is supported so this function is idempotent.

This is the opposite of builtins.unsafeDiscardOutputDependency.

Noogle detected

Aliases

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops/context.cc:97

static void prim_addDrvOutputDependencies(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    NixStringContext context;
    auto s = state.coerceToString(
        pos, *args[0], context, "while evaluating the argument passed to builtins.addDrvOutputDependencies");

    auto contextSize = context.size();
    if (contextSize != 1) {
        state.error<EvalError>("context of string '%s' must have exactly one element, but has %d", *s, contextSize)
            .atPos(pos)
            .debugThrow();
    }
    NixStringContext context2{
        (NixStringContextElem{std::visit(
            overloaded{
                [&](const NixStringContextElem::Opaque & c) -> NixStringContextElem::DrvDeep {
                    if (!c.path.isDerivation()) {
                        state.error<EvalError>("path '%s' is not a derivation", state.store->printStorePath(c.path))
                            .atPos(pos)
                            .debugThrow();
                    }
                    return NixStringContextElem::DrvDeep{
                        .drvPath = c.path,
                    };
                },
                [&](const NixStringContextElem::Built & c) -> NixStringContextElem::DrvDeep {
                    state
                        .error<EvalError>(
                            "`addDrvOutputDependencies` can only act on derivations, not on a derivation output such as '%1%'",
                            c.output)
                        .atPos(pos)
                        .debugThrow();
                },
                [&](const NixStringContextElem::DrvDeep & c) -> NixStringContextElem::DrvDeep {
                    /* Reuse original item because we want this to be idempotent. */
                    /* FIXME: Suspicious move out of const. This is actually a copy, so the comment
                     above does not make much sense. */
                    return std::move(c);
                },
            },
            context.begin()->raw)}),
    };

    v.mkString(*s, context2, state.mem);
}