query
On this page

storePath

builtins.storePath

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


Nix manual

Takes 1 arguments

path

This function allows you to define a dependency on an already existing store path. For example, the derivation attribute src = builtins.storePath /nix/store/f1d18v1y…-source causes the derivation to depend on the specified path, which must exist or be substitutable. Note that this differs from a plain path (e.g. src = /nix/store/f1d18v1y…-source) in that the latter causes the path to be copied again to the Nix store, resulting in a new path (e.g. /nix/store/ld01dnzc…-source-source).

Not available in pure evaluation mode.

See also builtins.fetchClosure.

Noogle detected

Detected Type
storePath :: StorePath -> StorePath

Implementation

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

src/libexpr/primops.cc:2016

static void prim_storePath(EvalState & state, CallSite callSite, Value * const * args, Value & v)
{
    if (state.settings.pureEval)
        state.error<EvalError>("'%s' is not allowed in pure evaluation mode", "builtins.storePath")
            .atPos(noPos)
            .debugThrow();

    NixStringContext context;
    SourcePath sourcePath = state.coerceToPath(
        noPos, *args[0], context, "while evaluating the first argument passed to 'builtins.storePath'");

    /* Resolve symlinks in ‘path’, unless ‘path’ itself is a symlink
       directly in the store.  The latter condition is necessary so
       e.g. nix-push does the right thing. */
    if (!state.store->isStorePath(sourcePath.path.abs()))
        sourcePath = sourcePath.resolveSymlinks(SymlinkResolution::Full);
    if (!state.store->isInStore(sourcePath.path.abs()))
        state.error<EvalError>("path '%1%' is not in the Nix store", sourcePath).atPos(noPos).debugThrow();
    auto storePath = state.store->toStorePath(sourcePath.path.abs()).first;
    if (!state.storeFS->getMount(CanonPath(state.store->printStorePath(storePath))) && !settings.readOnlyMode)
        state.store->getBuilder()->ensurePath(storePath);
    context.insert(NixStringContextElem::Opaque{.path = storePath});
    v.mkString(sourcePath.path.abs(), context, state.mem);
}