lib.isStorePath: fix false result when passed a path object

Since `isStorePath` relies on comparing against builtins.storeDir
(a string), we need to convert the input into a string as well.
This commit is contained in:
Tim Cuthbertson 2018-10-20 22:23:58 +11:00
parent 7a10601dc4
commit d984c55383
2 changed files with 7 additions and 4 deletions

View file

@ -502,9 +502,12 @@ rec {
=> false
*/
isStorePath = x:
isCoercibleToString x
&& builtins.substring 0 1 (toString x) == "/"
&& dirOf x == builtins.storeDir;
if isCoercibleToString x then
let str = toString x; in
builtins.substring 0 1 str == "/"
&& dirOf str == builtins.storeDir
else
false;
/* Convert string to int
Obviously, it is a bit hacky to use fromJSON that way.

View file

@ -112,7 +112,7 @@ runTests {
storePathAppendix = isStorePath
"${goodPath}/bin/python";
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
asPath = isStorePath goodPath;
asPath = isStorePath (/. + goodPath);
otherPath = isStorePath "/something/else";
otherVals = {
attrset = isStorePath {};