lib.isStorePath: Fix derivation detection
This commit is contained in:
parent
d3570a1e21
commit
b66d7dc0ce
@ -437,6 +437,13 @@ rec {
|
|||||||
*/
|
*/
|
||||||
fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
|
fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
|
||||||
|
|
||||||
|
/* Check whether a value can be coerced to a string */
|
||||||
|
isCoercibleToString = x:
|
||||||
|
builtins.elem (builtins.typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
|
||||||
|
(builtins.isList x && lib.all isCoercibleToString x) ||
|
||||||
|
x ? outPath ||
|
||||||
|
x ? __toString;
|
||||||
|
|
||||||
/* Check whether a value is a store path.
|
/* Check whether a value is a store path.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@ -450,7 +457,7 @@ rec {
|
|||||||
=> false
|
=> false
|
||||||
*/
|
*/
|
||||||
isStorePath = x:
|
isStorePath = x:
|
||||||
builtins.isString x
|
isCoercibleToString x
|
||||||
&& builtins.substring 0 1 (toString x) == "/"
|
&& builtins.substring 0 1 (toString x) == "/"
|
||||||
&& dirOf (builtins.toPath x) == builtins.storeDir;
|
&& dirOf (builtins.toPath x) == builtins.storeDir;
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ runTests {
|
|||||||
"${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
|
"${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
|
||||||
in {
|
in {
|
||||||
storePath = isStorePath goodPath;
|
storePath = isStorePath goodPath;
|
||||||
|
storePathDerivation = isStorePath (import ../.. {}).hello;
|
||||||
storePathAppendix = isStorePath
|
storePathAppendix = isStorePath
|
||||||
"${goodPath}/bin/python";
|
"${goodPath}/bin/python";
|
||||||
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
|
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
|
||||||
@ -106,6 +107,7 @@ runTests {
|
|||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
storePath = true;
|
storePath = true;
|
||||||
|
storePathDerivation = true;
|
||||||
storePathAppendix = false;
|
storePathAppendix = false;
|
||||||
nonAbsolute = false;
|
nonAbsolute = false;
|
||||||
asPath = true;
|
asPath = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user