Skip to content

lib.makeOverridable: observe <result>.__overriders#454997

Open
ShamrockLee wants to merge 3 commits intoNixOS:masterfrom
ShamrockLee:overriders-list-attribute
Open

lib.makeOverridable: observe <result>.__overriders#454997
ShamrockLee wants to merge 3 commits intoNixOS:masterfrom
ShamrockLee:overriders-list-attribute

Conversation

@ShamrockLee
Copy link
Copy Markdown
Contributor

@ShamrockLee ShamrockLee commented Oct 23, 2025

This PR solves lib.makeOverridable's not handling existing overriders beside overrideAttrs by introducing the __overriders attribute.

Such attribute contains the names of existing overriders of the attribute set.
When a lib.makeOverridable-like function adds a new overrider, it can check result.__overriders, decorates existing overriders, and add the name of the overriders it provide to the __overriders list.

This is an extensible solution/workaround to issues like <set>.override lost after <set>.overrideScope overriding (#447012) without substantial infrastructural changes (like what #273815 proposes).

This PR helps unblock improve PR #445668. Cc: @LunNova @bb010g

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.

@ShamrockLee ShamrockLee force-pushed the overriders-list-attribute branch from f13f741 to 8fa180d Compare October 23, 2025 19:07
@ShamrockLee ShamrockLee changed the title Overriders list attribute lib.makeOverridable: observe <result>.__overriders Oct 23, 2025
@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: lib The Nixpkgs function library labels Oct 23, 2025
@ShamrockLee ShamrockLee force-pushed the overriders-list-attribute branch from 8fa180d to 8c3729e Compare October 23, 2025 19:16
@ShamrockLee ShamrockLee marked this pull request as ready for review October 23, 2025 19:23
@ShamrockLee ShamrockLee requested a review from LunNova October 23, 2025 19:33
@ShamrockLee ShamrockLee force-pushed the overriders-list-attribute branch from 8c3729e to f109f51 Compare October 23, 2025 20:32
@ShamrockLee
Copy link
Copy Markdown
Contributor Author

I added a test case in lib/tests/misc.nix.

@ShamrockLee ShamrockLee force-pushed the overriders-list-attribute branch from f109f51 to 47424c0 Compare October 23, 2025 20:37
Copy link
Copy Markdown
Member

@emilazy emilazy left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!

FWIW, I think this shouldn’t block #445668 because llvmPackages.overrideScope didn’t previously exist – so its result not having .override is not a critical issue, just an unfortunate one. My review comments there were only about the need to ensure the Darwin stdenv’s use of it don’t clobber it, and to ensure that we can provide an .override that actually works there, but it seems that can be achieved by hand for now.

However, solving this problem in general is of course important. I hope you don’t mind me wanting to take some time to think about this approach, as this area of things is relevant to the by-name work I’m doing with @wolfgangwalther, and I worry a little about adding this to 25.11 and then potentially wanting to break it shortly after.

(To be clear, though, I don’t want to punt on this indefinitely, and although #273815 has been relevant to my thinking, I would not want to couple the kinds of solutions I’m thinking about to a meaningful breaking change in the stdenv.mkDerivation interface – I am hoping we can achieve something relatively general that preserves good backwards compatibility with our existing APIs, but I don’t object to smaller changes that work well.)

Comment thread lib/customisation.nix
Comment on lines +213 to +215
genAttrs (filter (
x: x != "override" && x != "overrideAttrs" && x != "overrideDerivation" && result ? ${x}
) result.__overriders) (name: fdrv: overrideResult (x: x.${name} fdrv))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An interesting option here would be to explicitly allow override here, which could potentially be used to allow migrating foo = bar.override { … }; definitions into by-name without breaking override interfaces. However, there are other complications there, with regards to the mirrorArgs stuff. (I got something to allow composing override interfaces working locally, but wasn’t entirely happy with the trade-offs.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An interesting option here would be to explicitly allow override here

Could you please elaborate?

We cannot implement the override attribute with overrideResult in lib.makeOverridable. It will always get overwritten.

As for overrideAttrs, we could do it here instead of defining explicitly above, but I'm worried about the potential performance implication.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can’t directly recall what I was thinking at the time, but I believe that what I meant was that we could allow packages to expose their own .override field rather than always overriding it, which lets you callPackage/.override some other package in by-name without having the usual callPackage override interface clobber the one you’d like to inherit. (Hence why we have some overrides directly in all-packages.nix still.) Though in further thinking about this whole class of problem I decided it was more complicated than that, because sometimes you don’t want to clobber the callPackage override interface in that way.

@ShamrockLee
Copy link
Copy Markdown
Contributor Author

FWIW, I think this shouldn’t block #445668 because llvmPackages.overrideScope didn’t previously exist – so its result not having .override is not a critical issue, just an unfortunate one. My review comments there were only about the need to ensure the Darwin stdenv’s use of it don’t clobber it, and to ensure that we can provide an .override that actually works there, but it seems that can be achieved by hand for now.

Thank you for explaining and clarifying it! The discussion thread is quite long under that PR, and I only have a vague impression about it.

However, solving this problem in general is of course important. I hope you don’t mind me wanting to take some time to think about this approach, as this area of things is relevant to the by-name work I’m doing with @wolfgangwalther, and I worry a little about adding this to 25.11 and then potentially wanting to break it shortly after.

This change affects the whole pkgs, and changes like this inherently require more consensus and review effort. It's sensible to defer its merge after the 25.11 release.

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 29, 2026
@ShamrockLee ShamrockLee force-pushed the overriders-list-attribute branch from 47424c0 to cbdd103 Compare March 30, 2026 09:36
@nixpkgs-ci nixpkgs-ci Bot requested a review from a team March 30, 2026 09:42
@nixpkgs-ci nixpkgs-ci Bot removed 2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

lib.customisation.makeOverridable: lose override after <scope>.overrideScope overriding

2 participants