From b66d7dc0ce684197181a2a8ec0859470137507aa Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 9 Mar 2018 17:21:12 -0500 Subject: [PATCH] lib.isStorePath: Fix derivation detection --- lib/strings.nix | 9 ++++++++- lib/tests/misc.nix | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/strings.nix b/lib/strings.nix index 9cbd1494a2b5..e6df7d99cb2e 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -437,6 +437,13 @@ rec { */ 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. Example: @@ -450,7 +457,7 @@ rec { => false */ isStorePath = x: - builtins.isString x + isCoercibleToString x && builtins.substring 0 1 (toString x) == "/" && dirOf (builtins.toPath x) == builtins.storeDir; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 1657ec33a46c..e10aea48e48e 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -93,6 +93,7 @@ runTests { "${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11"; in { storePath = isStorePath goodPath; + storePathDerivation = isStorePath (import ../.. {}).hello; storePathAppendix = isStorePath "${goodPath}/bin/python"; nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath))); @@ -106,6 +107,7 @@ runTests { }; expected = { storePath = true; + storePathDerivation = true; storePathAppendix = false; nonAbsolute = false; asPath = true;