about summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-12-28 23:10:44 +0100
committerRobert Hensing <robert@roberthensing.nl>2022-12-31 01:03:23 +0100
commit67cfc7a8f68776cbd7cf73e3c79b4cdd3ea102c4 (patch)
treed2b1b3238954cff1f32990f304dc9487328fffd3 /lib/strings.nix
parent393bdd70e2612a0071aaa74cf7f42989322ad86b (diff)
lib.strings: Add isSimpleCoercibleToString
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 20f6db08cebcf..039a9ed1db1cf 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -805,6 +805,17 @@ rec {
     x ? outPath ||
     x ? __toString;
 
+  /* Check whether a value can be coerced to a string,
+     The value must be a string, path, or attribute set.
+
+     This follows Nix's internal coerceToString(coerceMore = false) logic,
+     except for external types, for which we return false.
+   */
+  isSimpleCoercibleToString = x:
+    elem (typeOf x) [ "path" "string" ] ||
+    x ? outPath ||
+    x ? __toString;
+
   /* Check whether a value is a store path.
 
      Example: