query
On this page

derivationStrict

builtins.derivationStrict

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


Contribute
Enhance the ecosystem with your expertise! Contribute to fill the gaps in documentation. Your input can make a difference.

Implementation

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

src/libexpr/primops.cc:1425

static void prim_derivationStrict(EvalState & state, CallSite callSite, Value * const * args, Value & v)
{
    state.forceAttrs(*args[0], noPos, "while evaluating the argument passed to builtins.derivationStrict");

    auto attrs = args[0]->attrs();

    /* Figure out the name first (for stack backtraces). */
    auto nameAttr =
        state.getAttr(state.s.name, attrs, "in the attrset passed as argument to builtins.derivationStrict");

    std::string_view drvName;
    try {
        drvName = state.forceStringNoCtx(
            *nameAttr->value, noPos, "while evaluating the `name` attribute passed to builtins.derivationStrict");
    } catch (Error & e) {
        e.addTrace(state.positions[nameAttr->pos], "while evaluating the derivation attribute 'name'");
        throw;
    }

    try {
        derivationStrictInternal(state, drvName, attrs, v);
    } catch (Error & e) {
        Pos pos = state.positions[nameAttr->pos];
        /*
         * Here we call addTrace in a slightly unusual way:
         *
         * 1. We print the location as a string (instead of passing it via the
         * first argument to addTrace) to avoid a code snippet being printed.
         * While the location of the name attribute is a good hint, the exact
         * code there is irrelevant.
         *
         * Please keep in mind that error reporting is done on a best-effort
         * basis in nix. There is no single accurate location for a derivation,
         * as it often results from the composition of several functions
         * (derivationStrict, derivation, mkDerivation, mkPythonModule, etc.)
         *
         * 2. We use TracePrint::Always so that users who have not enabled
         * --show-trace will still get a full trace of the derivation
         * dependency chain that led to an evaluation error. The user may be
         * interested in the last item in the chain (the derivation with an
         * eval issue), an item near the top of the chain (a package they added
         * to their configuration), or an item in the middle of the chain (an
         * optional dependency they can remove with an override somewhere
         * because they don't need the corresponding functionality), so
         * displaying the entire chain is worth the space.
         */
        e.addTrace(
            nullptr,
            HintFmt(
                "while evaluating derivation '%s'\n"
                "  whose name attribute is located at %s",
                drvName,
                pos),
            TracePrint::Always);
        throw;
    }
}