From c5b82e49b33e95a17a675ad4c60da30c168ff020 Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 27 Oct 2025 19:05:09 +0000 Subject: [PATCH] aliases: add `warnAlias` --- maintainers/scripts/remove-old-aliases.py | 8 ++++---- pkgs/top-level/aliases.nix | 25 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/maintainers/scripts/remove-old-aliases.py b/maintainers/scripts/remove-old-aliases.py index c7d1292b3e1e..bceee1074844 100755 --- a/maintainers/scripts/remove-old-aliases.py +++ b/maintainers/scripts/remove-old-aliases.py @@ -98,8 +98,8 @@ def get_date_lists( date_too_complex_list.append(f"{lineno:>5} {line}") elif "= with " in line: date_too_complex_list.append(f"{lineno:>5} {line}") - elif "lib.warnOnInstantiate" in line or "warning" in line: - if 'lib.warnOnInstantiate "' in line: + elif "warnAlias" in line or "warning" in line: + if 'warnAlias "' in line: date_older_warning_list.append(line) else: date_too_complex_list.append(f"{lineno:>5} {line}") @@ -140,7 +140,7 @@ def convert(lines: list[str], convert_to: str) -> list[tuple[str, str]]: before_equal, after_equal = ( x.strip() for x in line.split("=", maxsplit=2) ) - if after_equal.startswith("lib.warnOnInstantiate"): + if after_equal.startswith("warnAlias"): after_equal = after_equal.split("\"", maxsplit=3)[2].strip() except ValueError as err: print(err, line, "\n") @@ -162,7 +162,7 @@ def convert(lines: list[str], convert_to: str) -> list[tuple[str, str]]: converted_lines[line] = converted elif convert_to == "warnings": converted = ( - f"{indent}{alias} = lib.warnOnInstantiate \"'{alias_unquoted}' has been" + f"{indent}{alias} = warnAlias \"'{alias_unquoted}' has been" f" renamed to/replaced by '{replacement}'\" {replacement};" f" # Converted to warning {datetime.today().strftime('%Y-%m-%d')}" ) diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index a2fe24a88240..764164c20131 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -231,6 +231,31 @@ let aliases: lib.mapAttrs (n: alias: removeRecurseForDerivations (checkInPkgs n alias)) aliases; plasma5Throws = mapAliases (lib.mapAttrs (k: _: makePlasma5Throw k) deprecatedPlasma5Packages); + + warnAlias = + msg: v: + if lib.isDerivation v then + lib.warnOnInstantiate msg v + else if lib.isAttrs v then + lib.mapAttrs (lib.warn msg) v + else if lib.isFunction v then + arg: lib.warn msg (v arg) + else if lib.isList v then + map (lib.warn msg) v + else if lib.isString v then + # Unlike the other cases, this changes the type of the value and + # is therefore a breaking change for some code, but it’s the best + # we can do. + { __toString = lib.warn msg (lib.const v); } + else + # Can’t do better than this, and a `throw` would be more + # disruptive for users… + # + # `nix search` flags up warnings already, so hopefully this won’t + # make things much worse until we have proper CI for aliases, + # especially since aliases of paths and numbers are presumably + # not common. + lib.warn msg v; in mapAliases {