query
On this page

isStorePath

lib.strings.isStorePath

Docs pulled from | This Revision | 10 minutes ago


Check whether a value x is a store path.

Inputs

x
1. Function argument

Type

isStorePath :: a -> bool

Examples

lib.strings.isStorePath usage example

isStorePath "/nix/store/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11/bin/python"
=> false
isStorePath "/nix/store/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11"
=> true
isStorePath pkgs.python
=> true
isStorePath [] || isStorePath 42 || isStorePath {} || …
=> false

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

isStorePath =
    x:
    if isStringLike x then
      let
        str = toString x;
      in
      substring 0 1 str == "/"
      && (
        dirOf str == storeDir
        # Match content‐addressed derivations, which _currently_ do not have a
        # store directory prefix.
        # This is a workaround for https://github.com/NixOS/nix/issues/12361
        # which was needed during the experimental phase of ca-derivations and
        # should be removed once the issue has been resolved.
        || builtins.match "/[0-9a-z]{52}" str != null
      )
    else
      false;