pathWith
lib.types.pathWith
Docs pulled from | This Revision | 18 days ago
Contribute
Enhance the ecosystem with your expertise! Contribute to fill the gaps in documentation. Your input can make a difference.
Noogle detected
Implementation
The following is the current implementation of this function.
{
inStore ? null,
absolute ? null,
}:
if inStore != null && absolute != null && inStore && !absolute then
throw "In pathWith, inStore means the path must be absolute"
else
mkOptionType {
name = "path";
description = (
(if absolute == null then "" else (if absolute then "absolute " else "relative "))
+ "path"
+ (
if inStore == null then "" else (if inStore then " in the Nix store" else " not in the Nix store")
)
);
descriptionClass = "noun";
merge = mergeEqualOption;
functor = defaultFunctor "path" // {
type = pathWith;
payload = { inherit inStore absolute; };
binOp = lhs: rhs: if lhs == rhs then lhs else null;
};
check =
x:
let
isInStore = hasStorePathPrefix (
if isPath x then
x
# Discarding string context is necessary to convert the value to
# a path and safe as the result is never used in any derivation.
else
/. + builtins.unsafeDiscardStringContext x
);
isAbsolute = substring 0 1 (toString x) == "/";
isExpectedType = (
if inStore == null || inStore then isStringLike x else isString x # Do not allow a true path, which could be copied to the store later on.
);
in
isExpectedType
&& (inStore == null || inStore == isInStore)
&& (absolute == null || absolute == isAbsolute);
}