Skip to content

Enable stdenv customization through (buildPython*.override { inherit stdenv; })#271762

Merged
ShamrockLee merged 4 commits intoNixOS:masterfrom
ShamrockLee:python-function-override
Oct 24, 2025
Merged

Enable stdenv customization through (buildPython*.override { inherit stdenv; })#271762
ShamrockLee merged 4 commits intoNixOS:masterfrom
ShamrockLee:python-function-override

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Dec 2, 2023

Description of changes

Now that #366593 has restored the missing .override to buildPythonPackage and buildPythonApplication, this allow specifying the stdenv used by the build helpers through buildPython*.override (as most build helpers do) instead of passing it directly into buildPython*.

The reason to move to buildPythonPackage.override { stdenv = ...; } from buildPythonPackage { stdenv = ...; } includes:

  1. The buildPython* { inherit stdenv; ...; } will be impossible/unfeasible when taking fixed-point arguments (buildPython* (finalAttrs: { ...; })). lib.extendMkDerivation is on its way, but we need a clean ground to integrate it into buildPython*.

  2. stdenv is a dependency buildPythonPackage would (directly or indirectly) get from pkgs through callPackage. It makes better sense to change it through the .override attribute provided by callPackage.

  3. In the future, we could get rid of all the special, impassable arguments, and pass everything properly either into stdenv.mkDerivation or through passthru. This way, we only need overrideAttrs to override attributes, without having to defined special overriders like overridePythonAttrs and for each language and framework. stdenv could neither be passed into stdenv.mkDerivation or through passthru, since stdenv.mkDerivaiton will add a stdenv attribute to the resulting derivation.

For package definition that used to be:

{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPyPi,
}:
buildPythonPackage rec {
  inherit stdenv;
  pname = "...";
  version = "...";
  src = fetchPypi {
    inherit pname source;
    hash = "...";
  };
}

can now become

{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPyPi,
}:
buildPythonPackage.override { inherit stdenv; } rec {
  pname = "...";
  version = "...";
  src = fetchPypi {
    inherit pname source;
    hash = "...";
  };
}

In the future, when buildPythonPackage also takes fixed-point arguments, we could write:

{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPyPi,
}:
buildPythonPackage.override { inherit stdenv; } (finalAttrs: {
  pname = "...";
  version = "...";
  src = fetchPypi {
    inherit (finalAttrs) pname source;
    hash = "...";
  };
})

This PR depends on #366593.
Initial effort for #271387.

Things done

  • Built on platform(s)
    • x86_64-linux (no rebuilds other than nixos-install-tools)
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Priorities

Add a 👍 reaction to pull requests you find important.

@ShamrockLee ShamrockLee requested a review from FRidh as a code owner December 2, 2023 21:47
@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes labels Dec 2, 2023
@ShamrockLee ShamrockLee mentioned this pull request Dec 2, 2023
12 tasks
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Dec 2, 2023
@ShamrockLee ShamrockLee force-pushed the python-function-override branch from 89f0bd1 to 279ab67 Compare December 3, 2023 23:05
@ShamrockLee
Copy link
Contributor Author

Simplify a bit.

@ShamrockLee
Copy link
Contributor Author

Reword the release note entry.

@ShamrockLee ShamrockLee force-pushed the python-function-override branch from 93fb0e3 to c1aee27 Compare March 10, 2024 12:17
@ShamrockLee ShamrockLee requested a review from Steinhagen March 10, 2024 12:20
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 10, 2024
@ShamrockLee ShamrockLee force-pushed the python-function-override branch from c1aee27 to 433a127 Compare March 10, 2024 12:37
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 10, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 3, 2024
@ShamrockLee ShamrockLee force-pushed the python-function-override branch from 433a127 to 4d3b925 Compare August 10, 2024 11:59
@ShamrockLee ShamrockLee requested a review from natsukium as a code owner August 10, 2024 11:59
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 10, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 1, 2024
@ShamrockLee ShamrockLee force-pushed the python-function-override branch from 4d3b925 to 62fce45 Compare January 22, 2025 18:12
@github-actions github-actions bot removed 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes labels Jan 22, 2025
@ShamrockLee ShamrockLee force-pushed the python-function-override branch from 5417064 to 71fee98 Compare October 22, 2025 22:52
@nixpkgs-ci nixpkgs-ci bot added the 8.has: changelog This PR adds or changes release notes label Oct 22, 2025
@ShamrockLee ShamrockLee force-pushed the python-function-override branch 3 times, most recently from a0f5f69 to e7d8504 Compare October 23, 2025 00:48
ShamrockLee and others added 4 commits October 23, 2025 14:51
On Nixpkgs >= 26.05 (or precisely, oldest supported release >= 25.11),
warn about the use of buildPython*'s deprecated argument `stdenv`.

Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
Copy link
Contributor

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

LGTM

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 23, 2025
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Oct 24, 2025

@MattSturgeon I wrote some test cases locally (with the modularized Python tests.overriding test-cases cherry-picked from #267296), and they passed. Should I push it here or should we do it in a subsequent PR?

@ShamrockLee
Copy link
Contributor Author

Anyway, let's merge before the all-breaking-changes restriction.

@ShamrockLee ShamrockLee added this pull request to the merge queue Oct 24, 2025
@MattSturgeon
Copy link
Contributor

If the tests are testing this PR's changes and/or testing that this PR doesn't break existing behaviour, then pushing them to this PR probably makes sense.

Merged via the queue into NixOS:master with commit dee46cb Oct 24, 2025
30 of 33 checks passed
@ShamrockLee ShamrockLee deleted the python-function-override branch October 24, 2025 15:15
@ShamrockLee
Copy link
Contributor Author

Apology for not reacting earlier. I'll open a PR for the tests tomorrow morning (UTC+8).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.severity: blocker This is preventing another PR or issue from being completed 6.topic: python Python is a high-level, general-purpose programming language. 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants