query
On this page

storePath

builtins.storePath

Primop
Docs pulled from | This Revision | about 19 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:1922

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

    NixStringContext context;
    auto path =
        state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to 'builtins.storePath'")
            .path;
    /* 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(path.abs()))
        path = CanonPath(canonPath(path.abs(), true).string());
    if (!state.store->isInStore(path.abs()))
        state.error<EvalError>("path '%1%' is not in the Nix store", path).atPos(pos).debugThrow();
    auto path2 = state.store->toStorePath(path.abs()).first;
    if (!settings.readOnlyMode)
        state.store->ensurePath(path2);
    context.insert(NixStringContextElem::Opaque{.path = path2});
    v.mkString(path.abs(), context, state.mem);
}