diff --git a/doc/release-notes/rl-2511.section.md b/doc/release-notes/rl-2511.section.md index 02b08039812b6..26a322b2e9611 100644 --- a/doc/release-notes/rl-2511.section.md +++ b/doc/release-notes/rl-2511.section.md @@ -9,6 +9,9 @@ and newer series. However, embedded chips without LSX (Loongson SIMD eXtension), such as 2K0300 SoC, are not supported. `pkgsCross.loongarch64-linux-embedded` can be used to build software and systems for these platforms. +- Package aliases now print a warning when used. This behaviour is controlled with the new `config.warnAliases` + which by default is `true`. + ## Backward Incompatibilities {#sec-nixpkgs-release-25.11-incompatibilities} diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index e34f83d9ce728..8e7d4eec9e3ac 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -1,4 +1,4 @@ -lib: self: super: +lib': self: _super: ### Deprecated aliases - for backward compatibility ### Please maintain this list in ASCIIbetical ordering. @@ -17,8 +17,6 @@ lib: self: super: # distro aliases such as: # debian-package-name -> nixos-package-name -with self; - let # Removing recurseForDerivation prevents derivations of aliased attribute set # to appear while listing all the packages available. @@ -46,7 +44,7 @@ let "${p} has been renamed to ${p3} since ${p4} is also available. Note that upgrade caused data loss for some users so backup is recommended (see NixOS 24.11 release notes for details)"; deprecatedPlasma5Packages = { - inherit (plasma5Packages) + inherit (self.plasma5Packages) akonadi akregator arianna @@ -178,7 +176,7 @@ let zanshin ; - inherit (plasma5Packages.thirdParty) + inherit (self.plasma5Packages.thirdParty) krohnkite krunner-ssh krunner-symbols @@ -188,7 +186,7 @@ let plasma-applet-virtual-desktop-bar ; - inherit (libsForQt5) + inherit (self.libsForQt5) sddm ; }; @@ -209,15 +207,62 @@ let # Make sure that we are not shadowing something from all-packages.nix. checkInPkgs = n: alias: - if builtins.hasAttr n super then throw "Alias ${n} is still in all-packages.nix" else alias; + if builtins.hasAttr n _super then throw "Alias ${n} is still in all-packages.nix" else alias; + + # `config.warnAliases` machinery + # These are no-ops when warnAliases=false + + selfWithAliasWarningNames = + if _super.config.warnAliases then + lib.mapAttrs ( + name: package: + if lib.isDerivation package then + # smuggle the attribute name of each package + package // { __aliasWarningAttrName = name; } + else + package + ) self + else + self; + + addAliasWarnOnInstantiate = + if _super.config.warnAliases then + name: alias: + if !alias ? __aliasWarningAttrName then + alias + else + # our lib.warnOnInstantiate override also removes __aliasWarningAttrName + lib.warnOnInstantiate "'${name}' has been renamed to/replaced by '${alias.__aliasWarningAttrName}'" + alias + else + name: alias: alias; + + lib = lib'.extend ( + final: prev: + lib'.optionalAttrs _super.config.warnAliases { + # make warnOnInstantiate also remove __aliasWarningAttrName + # to enable tailoring alias warnings without producing double warnings + warnOnInstantiate = + message: package: + prev.warnOnInstantiate message (prev.removeAttrs package [ "__aliasWarningAttrName" ]); + } + ); mapAliases = aliases: lib.mapAttrs ( - n: alias: removeDistribute (removeRecurseForDerivations (checkInPkgs n alias)) + name: alias: + addAliasWarnOnInstantiate name ( + removeDistribute (removeRecurseForDerivations (checkInPkgs name alias)) + ) ) aliases; in +with selfWithAliasWarningNames; +let + pkgs = selfWithAliasWarningNames; +in + mapAliases { # Added 2018-07-16 preserve, reason: forceSystem should not be used directly in Nixpkgs. forceSystem = system: _: (import self.path { localSystem = { inherit system; }; }); diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index 840c4e03e92d6..0e35ce604e7ad 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -101,6 +101,23 @@ let ''; }; + warnAliases = mkOption { + type = types.bool; + default = true; + description = '' + Whether to show warnings when accessing aliases. + + While it is true by default it is perfectly okay to disable + this. For example it make sense to disable alias warnings when + running `nix search`. + + This is a tool to gently let you know which attributes in your code + are aliases. Projects that aren't Nixpkgs should however be cautious + of instantly removing all usages of aliases, as migrating too soon + can break compatibility with the stable Nixpkgs releases. + ''; + }; + allowUnfree = mkOption { type = types.bool; default = false;