Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Dec 2, 2023

Description of changes

This PR brings the missing .override back to buildPythonPackage and buildPythonApplication, and allow specifying the stdenv used by the build helpers through buildPython*.override (as most build helpers do) instead of passing it 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 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 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 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
Fix `makeOverridablePythonPackage` in python-package-base.nix
and unshadow `buildPython*.override`.

This makes it possible to override the dependencies of buildPython*.
E.g., `buildPythonPackage.override { unzip = unzip-custom; }`
returns a derived version of `buildPythonPackage` with
the `unzip` package overridden with `unzip-custom`.
@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 labels Jan 22, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 22, 2025
@ShamrockLee ShamrockLee changed the title buildPython*: bring back <function>.override and enable stdenv customization through (buildPython*.override { inherit stdenv; }) Enable stdenv customization through (buildPython*.override { inherit stdenv; }) Jan 22, 2025
@nix-owners nix-owners bot requested a review from mweinelt January 22, 2025 18:13
@github-actions github-actions bot added 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux 8.has: documentation This PR adds or changes documentation and removed 10.rebuild-linux: 1-10 labels Jan 22, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1 10.rebuild-darwin: 1-10 10.rebuild-linux: 1 10.rebuild-linux: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 22, 2025
@ShamrockLee ShamrockLee force-pushed the python-function-override branch 2 times, most recently from 8a648bc to 6ced5d4 Compare January 22, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants