···1818 isInt
1919 isList
2020 isAttrs
2121+ isPath
2122 isString
2223 match
2324 parseDrvName
···395396 */
396397 toShellVar = name: value:
397398 lib.throwIfNot (isValidPosixName name) "toShellVar: ${name} is not a valid shell variable name" (
398398- if isAttrs value && ! isCoercibleToString value then
399399+ if isAttrs value && ! isStringLike value then
399400 "declare -A ${name}=(${
400401 concatStringsSep " " (lib.mapAttrsToList (n: v:
401402 "[${escapeShellArg n}]=${escapeShellArg v}"
···798799 in lib.warnIf (!precise) "Imprecise conversion from float to string ${result}"
799800 result;
800801801801- /* Check whether a value can be coerced to a string */
802802- isCoercibleToString = x:
803803- elem (typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
804804- (isList x && lib.all isCoercibleToString x) ||
802802+ /* Soft-deprecated function. While the original implementation is available as
803803+ isConvertibleWithToString, consider using isStringLike instead, if suitable. */
804804+ isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
805805+ "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."
806806+ isConvertibleWithToString;
807807+808808+ /* Check whether a list or other value can be passed to toString.
809809+810810+ Many types of value are coercible to string this way, including int, float,
811811+ null, bool, list of similarly coercible values.
812812+ */
813813+ isConvertibleWithToString = x:
814814+ isStringLike x ||
815815+ elem (typeOf x) [ "null" "int" "float" "bool" ] ||
816816+ (isList x && lib.all isConvertibleWithToString x);
817817+818818+ /* Check whether a value can be coerced to a string.
819819+ The value must be a string, path, or attribute set.
820820+821821+ String-like values can be used without explicit conversion in
822822+ string interpolations and in most functions that expect a string.
823823+ */
824824+ isStringLike = x:
825825+ isString x ||
826826+ isPath x ||
805827 x ? outPath ||
806828 x ? __toString;
807829···818840 => false
819841 */
820842 isStorePath = x:
821821- if !(isList x) && isCoercibleToString x then
843843+ if isStringLike x then
822844 let str = toString x; in
823845 substring 0 1 str == "/"
824846 && dirOf str == storeDir
+3-3
lib/types.nix
···5454 concatStringsSep
5555 escapeNixString
5656 hasInfix
5757- isCoercibleToString
5757+ isStringLike
5858 ;
5959 inherit (lib.trivial)
6060 boolToString
···227227 merge = loc: defs:
228228 let
229229 getType = value:
230230- if isAttrs value && isCoercibleToString value
230230+ if isAttrs value && isStringLike value
231231 then "stringCoercibleSet"
232232 else builtins.typeOf value;
233233···479479 path = mkOptionType {
480480 name = "path";
481481 descriptionClass = "noun";
482482- check = x: isCoercibleToString x && builtins.substring 0 1 (toString x) == "/";
482482+ check = x: isStringLike x && builtins.substring 0 1 (toString x) == "/";
483483 merge = mergeEqualOption;
484484 };
485485
+1-1
nixos/modules/services/misc/nix-daemon.nix
···4242 else if isDerivation v then toString v
4343 else if builtins.isPath v then toString v
4444 else if isString v then v
4545- else if strings.isCoercibleToString v then toString v
4545+ else if strings.isConvertibleWithToString v then toString v
4646 else abort "The nix conf value: ${toPretty {} v} can not be encoded";
47474848 mkKeyValue = k: v: "${escape [ "=" ] k} = ${mkValueString v}";