Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release-notes/rl-2511.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
61 changes: 53 additions & 8 deletions pkgs/top-level/aliases.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib: self: super:
lib': self: _super:

### Deprecated aliases - for backward compatibility
### Please maintain this list in ASCIIbetical ordering.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,7 +176,7 @@ let
zanshin
;

inherit (plasma5Packages.thirdParty)
inherit (self.plasma5Packages.thirdParty)
krohnkite
krunner-ssh
krunner-symbols
Expand All @@ -188,7 +186,7 @@ let
plasma-applet-virtual-desktop-bar
;

inherit (libsForQt5)
inherit (self.libsForQt5)
sddm
;
};
Expand All @@ -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 (

@hsjobeki hsjobeki Jun 20, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use of extend was discouraged. cc @roberth.
possibly extend lib without calling extend,
I am a bit worried about this because after this PR:
pkgs.lib != lib

A similar change was made in flake.nix and was highly regreted. We have to maintain that parallelism now and people are confused because about why lib is having different functions sometimes - depending how you import it.

Maybe bind __aliasWarningAttrName = { warnAliases = true; } ? That would also allow perPackage decisions which by default inherit true from the config of pkgs ?
(Just playing with ideas here)

@pbsds pbsds Jun 25, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming lib to _lib in the file with a comment about how only using the "whitelisted" functions from a inherit (_lib) ...; in the let binding is allowed? Then we're free to make custom versions of some of the lib functions.

Maybe bind __aliasWarningAttrName = { warnAliases = true; } ? That would also allow perPackage decisions which by default inherit true from the config of pkgs ?
(Just playing with ideas here)

I don't quite understand what you mean by this nor what it achieves.

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; }; });
Expand Down
17 changes: 17 additions & 0 deletions pkgs/top-level/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down