summaryrefslogtreecommitdiff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-03-14 23:29:08 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-03-15 19:42:45 +0100
commit5e8b9de7285497e4ef749eb9c55916dd26fecb88 (patch)
treef50d4841588ffdbc9e411db506159b201e256aab /lib/strings.nix
parentlib.strings: Deprecate path prefix/suffix/infix arguments (diff)
downloadnixpkgs-5e8b9de7285497e4ef749eb9c55916dd26fecb88.tar.gz
lib.strings.normalizePath: Deprecate for path values
There's no need to call this function on path data types, and it's confusing with the new lib.path library functions
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 963d937947f2..be4e8ece5936 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -207,7 +207,20 @@ rec {
normalizePath "/a//b///c/"
=> "/a/b/c/"
*/
- normalizePath = s: (builtins.foldl' (x: y: if y == "/" && hasSuffix "/" x then x else x+y) "" (stringToCharacters s));
+ normalizePath = s:
+ warnIf
+ (isPath s)
+ ''
+ lib.strings.normalizePath: The argument (${toString s}) is a path value, but only strings are supported.
+ Path values are always normalised in Nix, so there's no need to call this function on them.
+ This function also copies the path to the Nix store and returns the store path, the same as "''${path}" will, which may not be what you want.
+ This behavior is deprecated and will throw an error in the future.''
+ (
+ builtins.foldl'
+ (x: y: if y == "/" && hasSuffix "/" x then x else x+y)
+ ""
+ (stringToCharacters s)
+ );
/* Depending on the boolean `cond', return either the given string
or the empty string. Useful to concatenate against a bigger string.