From d984c553832fad99ee48e512252c0f2f27632789 Mon Sep 17 00:00:00 2001 From: Tim Cuthbertson Date: Sat, 20 Oct 2018 22:23:58 +1100 Subject: 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. --- lib/strings.nix | 9 ++++++--- lib/tests/misc.nix | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/strings.nix b/lib/strings.nix index 0c4095bb55cd..99399459bb48 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -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. diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 853d911cdc81..1604fbb39cbb 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -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 {}; -- cgit 1.4.1