From 834f0d660a79e8f08c108237d76fc1b42024289b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 31 Dec 2022 00:42:22 +0100 Subject: [PATCH] lib.strings: isMoreCoercibleString -> isConvertibleWithToString Yes, this function name is inconveniently long, but it is important for the name to explicitly reference the function and not be mistaken for the implicit string conversions, which only happen for a smaller set of values. --- lib/strings.nix | 11 ++++++----- nixos/modules/services/misc/nix-daemon.nix | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index 0130ea37fb1b..89574bc8367c 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -798,19 +798,20 @@ rec { in lib.warnIf (!precise) "Imprecise conversion from float to string ${result}" result; - /* Soft-deprecated name for isMoreCoercibleToString */ + /* Soft-deprecated function. While the original implementation is available as + isConvertibleWithToString, consider using isStringLike instead, if suitable. */ isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305) - "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; + "lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isConvertibleWithToString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles." + isConvertibleWithToString; /* Check whether a list or other value can be passed to toString. Many types of value are coercible to string this way, including int, float, null, bool, list of similarly coercible values. */ - isMoreCoercibleToString = x: + isConvertibleWithToString = x: elem (typeOf x) [ "path" "string" "null" "int" "float" "bool" ] || - (isList x && lib.all isMoreCoercibleToString x) || + (isList x && lib.all isConvertibleWithToString x) || x ? outPath || x ? __toString; diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix index 98d5150f2436..9863cc8e574c 100644 --- a/nixos/modules/services/misc/nix-daemon.nix +++ b/nixos/modules/services/misc/nix-daemon.nix @@ -42,7 +42,7 @@ let else if isDerivation v then toString v else if builtins.isPath v then toString v else if isString v then v - else if strings.isMoreCoercibleToString v then toString v + else if strings.isConvertibleWithToString v then toString v else abort "The nix conf value: ${toPretty {} v} can not be encoded"; mkKeyValue = k: v: "${escape [ "=" ] k} = ${mkValueString v}";