git.iko.soy/typeable/nixpkgs
on master help sign in
lib.isStorePath: Fix derivation detection
commitb66d7dc0ce684197181a2a8ec0859470137507aa authorShea Levy <shea@shealevy.com> dateFri 9 Mar 2018, 17:21 (9 years ago) parentd3570a1
2 files changed+10−1
lib/strings.nix+8−1 lib/tests/misc.nix+2
lib/strings.nix+8−1
@@ -437,6 +437,13 @@ rec {
437437 */
438438 fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
439439
440+ /* Check whether a value can be coerced to a string */
441+ isCoercibleToString = x:
442+ builtins.elem (builtins.typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
443+ (builtins.isList x && lib.all isCoercibleToString x) ||
444+ x ? outPath ||
445+ x ? __toString;
446+
440447 /* Check whether a value is a store path.
441448
442449 Example:
@@ -450,7 +457,7 @@ rec {
450457 => false
451458 */
452459 isStorePath = x:
453− builtins.isString x
460+ isCoercibleToString x
454461 && builtins.substring 0 1 (toString x) == "/"
455462 && dirOf (builtins.toPath x) == builtins.storeDir;
456463
lib/tests/misc.nix+2
@@ -93,6 +93,7 @@ runTests {
9393 "${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
9494 in {
9595 storePath = isStorePath goodPath;
96+ storePathDerivation = isStorePath (import ../.. {}).hello;
9697 storePathAppendix = isStorePath
9798 "${goodPath}/bin/python";
9899 nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
@@ -106,6 +107,7 @@ runTests {
106107 };
107108 expected = {
108109 storePath = true;
110+ storePathDerivation = true;
109111 storePathAppendix = false;
110112 nonAbsolute = false;
111113 asPath = true;