Skip to content

lib.customisation: add getFinalPassthruWith for unified missing finalAttrs.passthru.<attr> handling#446760

Open
ShamrockLee wants to merge 3 commits intoNixOS:masterfrom
ShamrockLee:lib-final-passthru
Open

lib.customisation: add getFinalPassthruWith for unified missing finalAttrs.passthru.<attr> handling#446760
ShamrockLee wants to merge 3 commits intoNixOS:masterfrom
ShamrockLee:lib-final-passthru

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Sep 27, 2025

Following the increased adoption of fixed-point attributes (finalAttrs: { }) and <pkg>.overrideAttrs-based overriding, some arguments are referenced and overridden under finalAttrs.passthru, accidental overriting/emptying of the passthru attributes could result in surprising errors/behavioural changes that is hard to identify and debug.

This PR provides two new Nixpkgs Library functions, getFinalPassthruWith and getFinalPassthruMissingMessage, which gets the attribute from finalAttrs.passthru and fall back to specified behaviours with informative error/warning message including the possible position of the last passthru overriding.

See the followings for context:

Aside from buildGoModule, recent buildPythonPackage overriding improvement will also benefit from this library function.

Questions:

  • Should these functions be defined under lib.meta instead of lib.customisation?
  • Should getFinalPassthruWith has a signature of { handler, prefix, finalAttrs } -> attrName -> Any instead of { handler, prefix } -> finalAttrs -> attrName -> Any?

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 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. 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: lib The Nixpkgs function library labels Sep 27, 2025
@ShamrockLee ShamrockLee marked this pull request as ready for review September 27, 2025 20:48
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 27, 2025
@ShamrockLee
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446760
Commit: d2d22c30d551018376fc9fff0479694416eb104b


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • nixpkgs-manual

@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 27, 2025
@ShamrockLee
Copy link
Contributor Author

I added some test cases.

@ShamrockLee ShamrockLee changed the title lib.customisation: add getFinalPassthruWith and getFinalPassthruMissingMessage for unified missing finalPassthru.<attr> handling lib.customisation: add getFinalPassthruWith for unified missing finalPassthru.<attr> handling Sep 28, 2025
@ShamrockLee ShamrockLee changed the title lib.customisation: add getFinalPassthruWith for unified missing finalPassthru.<attr> handling lib.customisation: add getFinalPassthruWith for unified missing finalAttrs.passthru.<attr> handling Sep 28, 2025
@philiptaron
Copy link
Contributor

Due to the SC election, I haven't had a chance to look at this.

@ShamrockLee
Copy link
Contributor Author

Due to the SC election, I haven't had a chance to look at this.

No hurry.

This kind of interface design takes time to gather broader inputs and consensus. We might also update the fixed-point arguments documentation afterward. In addition, backporting this function and substituting existing warning/throwing causes no rebuilds.

@wolfgangwalther
Copy link
Contributor

I have not looked at this our thought about this in-depth, but my gut tells me this is overly specific to be put in lib.

@ShamrockLee
Copy link
Contributor Author

I have not looked at this our thought about this in-depth, but my gut tells me this is overly specific to be put in lib.

This is a very valid point. this function is tightly coupled to the stdenv.mkDerivation interface, and downstream projects using the Nixpkgs library does not necesarily use stdenv.mkDerivation. (It's different from lib.extendMkDerivation; the latter is essentially lib.extends with argument exclusion.)

Should we move it under stdenv?

Still, considering the existence of lib.meta and lib.meta.setPrio, how independent of Nixpkgs library from pkgs do we expect?

@philiptaron
Copy link
Contributor

Should we move it under stdenv?

The alternative, in my mind, is to put it next to make-derivation.nix, maybe in pkgs/stdenv/generic/passthru.nix and have that specific file be imported by pkgs/test/stdenv/default.nix and tested that way. Much of what's in make-derivation.nix could be extracted and unit tested in this way, I note.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: lib The Nixpkgs function library 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants