Skip to content

Commit

Permalink
buildPython*: deprecate improvised <pkg>.override
Browse files Browse the repository at this point in the history
Deprecate the .override attribute added by
buildPythonPackage and buildPythonApplication to simplify overriding.

This attribute is mostly shadowed by the one added by `callPackage`
(i.e. the typical `<pkg>.override`), so the impact should be minimal.
  • Loading branch information
ShamrockLee committed Dec 6, 2023
1 parent 3e30553 commit c848291
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

The same rules apply to `buildPythonApplication`.

- The improvised `<pkg>.override` attribute added to the packages returned by `buildPythonPackage` or `buildPythonApplication` is deprecated in favor of
- `overridePythonAttrs`
- `overrideAttrs`
- `override` added by `callPackage` (the typical [`<pkg>.override`](https://nixos.org/manual/nixpkgs/unstable/#sec-pkg-override)).

The impact should be minimal, as the improvised `<pkgs>.override` attribute is shadowed by the typical `<pkgs>.override`, as long as the package definition is called using `callPackage`.

## Other Notable Changes {#sec-release-24.05-notable-changes}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
27 changes: 23 additions & 4 deletions pkgs/development/interpreters/python/python-packages-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ let
(fdrv: decorate (f.override fdrv));
};

deprecateOutputAttributes = f: origArgs:
let
result = f origArgs;
in
if lib.isAttrs result
then {
# Output attributes to deprecate

# Throw error when the deprecated improvised <pkg>.override is accessed
# This will most likely be shadowed by the typical <pkg>.override
# added by another callPackage onto package definitions.
override = throw ''
Attribute 'override' added by buildPython* is deprecated.
Use 'overridePythonAttrs' or 'overrideAttrs' instead, or add '<pkgs>.override' using callPackage.
'';

} // result
else if builtins.isFunction result
then lib.mirrorFunctionArgs result result
else result;

compatCustomStdenv = f: origArgs: (
if origArgs?stdenv then
f.override { inherit (origArgs) stdenv; }
Expand All @@ -59,10 +80,8 @@ let
# This ensures that the function argument of buildPython* is always mirrored
# and that buildPython*.override is always preserved.
decorateBuildPyhon = f: lib.pipe f (map preserveFunctionOverride [
# OBSOLETE: add improvised <pkg>.override
# This will most likely be shadowed by the typical <pkg>.override
# added by another callPackage onto package definitions.
lib.makeOverridable
# Throw error upon accessing attempt to deprecated output attributes
deprecateOutputAttributes
# Take the obsolete input argument `stdenv`
# and pass as `buildPython*.override { stdenv = stdenv; }`
# TODO: Remove this after Nixpkgs 24.11 branch-off
Expand Down

0 comments on commit c848291

Please sign in to comment.