lib/types: check paths in pathWith with hasStorePathPrefix

This permits usage of content‐addressed derivations and has the added
benefit of checking normalised paths.
This commit is contained in:
Mikael Voss 2025-03-05 14:45:36 +01:00
parent bf790d1a7f
commit 931f464581
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -669,7 +669,14 @@ let
check =
x:
let
isInStore = builtins.match "${builtins.storeDir}/[^.].*" (toString x) != null;
isInStore = lib.path.hasStorePathPrefix (
if builtins.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 = builtins.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.