summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-12-31 00:38:16 +0100
committerRobert Hensing <robert@roberthensing.nl>2022-12-31 01:33:46 +0100
commit872a24ebbc8056142f7930cc0f775237c4ca83f7 (patch)
tree6007bce61d284103a1debd0e95d42f8df23ac97b
parent5b8de3d9d85c121fd027608fe0c049356c6eea30 (diff)
downloadnixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar.gz
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar.bz2
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar.lz
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar.xz
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.tar.zst
nixpkgs-872a24ebbc8056142f7930cc0f775237c4ca83f7.zip
lib.strings: isSimpleCoercibleString -> isStringLike
-rw-r--r--lib/strings.nix14
-rw-r--r--lib/types.nix6
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 6d2462d03b2..0130ea37fb1 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -395,7 +395,7 @@ rec {
   */
   toShellVar = name: value:
     lib.throwIfNot (isValidPosixName name) "toShellVar: ${name} is not a valid shell variable name" (
-    if isAttrs value && ! isSimpleCoercibleToString value then
+    if isAttrs value && ! isStringLike value then
       "declare -A ${name}=(${
         concatStringsSep " " (lib.mapAttrsToList (n: v:
           "[${escapeShellArg n}]=${escapeShellArg v}"
@@ -800,7 +800,7 @@ rec {
 
   /* Soft-deprecated name for isMoreCoercibleToString */
   isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
-    "lib.strings.isCoercibleToString is deprecated in favor of either isSimpleCoercibleToString or isMoreCoercibleString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
+    "lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isMoreCoercibleString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
     isMoreCoercibleToString;
 
   /* Check whether a list or other value can be passed to toString.
@@ -814,13 +814,13 @@ rec {
     x ? outPath ||
     x ? __toString;
 
-  /* Check whether a value can be coerced to a string,
+  /* 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.
+     String-like values can be used without explicit conversion in
+     string interpolations and in most functions that expect a string.
    */
-  isSimpleCoercibleToString = x:
+  isStringLike = x:
     elem (typeOf x) [ "path" "string" ] ||
     x ? outPath ||
     x ? __toString;
@@ -838,7 +838,7 @@ rec {
        => false
   */
   isStorePath = x:
-    if isSimpleCoercibleToString x then
+    if isStringLike x then
       let str = toString x; in
       substring 0 1 str == "/"
       && dirOf str == storeDir
diff --git a/lib/types.nix b/lib/types.nix
index deeff36b4a4..666e6502d16 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -54,7 +54,7 @@ let
     concatStringsSep
     escapeNixString
     hasInfix
-    isSimpleCoercibleToString
+    isStringLike
     ;
   inherit (lib.trivial)
     boolToString
@@ -227,7 +227,7 @@ rec {
       merge = loc: defs:
         let
           getType = value:
-            if isAttrs value && isSimpleCoercibleToString value
+            if isAttrs value && isStringLike value
             then "stringCoercibleSet"
             else builtins.typeOf value;
 
@@ -479,7 +479,7 @@ rec {
     path = mkOptionType {
       name = "path";
       descriptionClass = "noun";
-      check = x: isSimpleCoercibleToString x && builtins.substring 0 1 (toString x) == "/";
+      check = x: isStringLike x && builtins.substring 0 1 (toString x) == "/";
       merge = mergeEqualOption;
     };