From d33127863ecda07ddd292d9bad7f8717f69430a0 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sat, 3 Feb 2024 16:13:04 +0100 Subject: [PATCH] lib: make deprecation warnings consistent The deprecation warnings in lib were wildly inconsistent. Different formulations were used in different places for the same meaning. Some warnings used builtins.trace instead of lib.warn, which prevents silencing; one even only had a comment instead. Make everything more uniform. --- lib/attrsets.nix | 9 +++++---- lib/lists.nix | 6 +++--- lib/options.nix | 2 +- lib/strings.nix | 4 ++-- lib/trivial.nix | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 99b686918453..0e896a93156d 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -3,7 +3,7 @@ let inherit (builtins) head tail length; - inherit (lib.trivial) id mergeAttrs; + inherit (lib.trivial) id mergeAttrs warn; inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName; inherit (lib.lists) foldr foldl' concatMap concatLists elemAt all partition groupBy take foldl; in @@ -1197,9 +1197,10 @@ rec { (x // y) // mask; # DEPRECATED - zipWithNames = zipAttrsWithNames; + zipWithNames = warn + "lib.zipWithNames is a deprecated alias of lib.zipAttrsWithNames." zipAttrsWithNames; # DEPRECATED - zip = builtins.trace - "lib.zip is deprecated, use lib.zipAttrsWith instead" zipAttrsWith; + zip = warn + "lib.zip is a deprecated alias of lib.zipAttrsWith." zipAttrsWith; } diff --git a/lib/lists.nix b/lib/lists.nix index 9397acf148fc..b612bc16697e 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -2,7 +2,7 @@ { lib }: let inherit (lib.strings) toInt; - inherit (lib.trivial) compare min id; + inherit (lib.trivial) compare min id warn; inherit (lib.attrsets) mapAttrs; inherit (lib.lists) sort; in @@ -848,8 +848,8 @@ rec { crossLists (x:y: "${toString x}${toString y}") [[1 2] [3 4]] => [ "13" "14" "23" "24" ] */ - crossLists = builtins.trace - "lib.crossLists is deprecated, use lib.cartesianProductOfSets instead" + crossLists = warn + "lib.crossLists is deprecated, use lib.cartesianProductOfSets instead." (f: foldl (fs: args: concatMap (f: map f args) fs) [f]); diff --git a/lib/options.nix b/lib/options.nix index 9c10dfc8b36a..f5012848b05a 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -379,7 +379,7 @@ rec { if ! isString text then throw "literalExpression expects a string." else { _type = "literalExpression"; inherit text; }; - literalExample = lib.warn "literalExample is deprecated, use literalExpression instead, or use literalMD for a non-Nix description." literalExpression; + literalExample = lib.warn "lib.literalExample is deprecated, use lib.literalExpression instead, or use lib.literalMD for a non-Nix description." literalExpression; /* Transition marker for documentation that's already migrated to markdown syntax. This is a no-op and no longer needed. diff --git a/lib/strings.nix b/lib/strings.nix index 49654d8abaa7..7083576dd529 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -561,7 +561,7 @@ rec { [""" "'" "<" ">" "&"]; # warning added 12-12-2022 - replaceChars = lib.warn "replaceChars is a deprecated alias of replaceStrings, replace usages of it with replaceStrings." builtins.replaceStrings; + replaceChars = lib.warn "lib.replaceChars is a deprecated alias of lib.replaceStrings." builtins.replaceStrings; # Case conversion utilities. lowerChars = stringToCharacters "abcdefghijklmnopqrstuvwxyz"; @@ -1133,7 +1133,7 @@ rec { "/prefix/nix-profiles-library-paths.patch" "/prefix/compose-search-path.patch" ] */ - readPathsFromFile = lib.warn "lib.readPathsFromFile is deprecated, use a list instead" + readPathsFromFile = lib.warn "lib.readPathsFromFile is deprecated, use a list instead." (rootPath: file: let lines = lib.splitString "\n" (readFile file); diff --git a/lib/trivial.nix b/lib/trivial.nix index f27cfb04f074..58620006de15 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -230,7 +230,7 @@ in { else if lib.pathExists revisionFile then lib.fileContents revisionFile else default; - nixpkgsVersion = builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!" version; + nixpkgsVersion = warn "lib.nixpkgsVersion is a deprecated alias of lib.version." version; /* Determine whether the function is being called from inside a Nix shell.