Skip to content

lib.applyToOverridable: init#266232

Closed
ShamrockLee wants to merge 2 commits intoNixOS:masterfrom
ShamrockLee:lib-apply-to-overridable
Closed

lib.applyToOverridable: init#266232
ShamrockLee wants to merge 2 commits intoNixOS:masterfrom
ShamrockLee:lib-apply-to-overridable

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 8, 2023

Description of changes

This PR defines a function lib.applyToOverridable that make sure that an overridable (an attribute set one can override) behaves when updating its attributes directly (i.e. not by overriding).

Without it, the updating will be lost once the overridable is overridden. For example, ((lib.extendDerivation true { ans = 42; } pkgs.hello).override { }).ans throws error: attribute 'ans' missing. This is relevant when applying extendDerivation to a package produced by stdenv.mkDerivation.

Packages produced by many language-specific build helpers suffers from such overrideAttrs misbehave. For example, pkgs.python3Packages.six.updateScript evaluates successfully, but (pkgs.python311Packages.six.overrideAttrs { }).updateScript throws error: attribute 'updateScript' missing. I'm not planning to fix them here, as they can be improved through lib.extendMkDerivationModified in the future, which internally calls lib.applyToOverridable. It sounds awkward to change them twice.

This is split from #234651

This depends on #265710 for lib.mirrorFunctionArgs.

Things done

  • Built on platform(s)
    • x86_64-linux
    • 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/)
  • 23.11 Release Notes (or backporting 23.05 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.

@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 6.topic: lib The Nixpkgs function library labels Nov 8, 2023
@ShamrockLee ShamrockLee force-pushed the lib-apply-to-overridable branch from bd8adaf to ab8e5fc Compare November 8, 2023 11:44
@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Nov 8, 2023
@ShamrockLee ShamrockLee force-pushed the lib-apply-to-overridable branch from ab8e5fc to 6f87b0b Compare November 8, 2023 13:39
@github-actions github-actions bot removed the 6.topic: python Python is a high-level, general-purpose programming language. label Nov 8, 2023
@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 Nov 8, 2023
@ShamrockLee ShamrockLee force-pushed the lib-apply-to-overridable branch from 6f87b0b to 38fb7b6 Compare November 9, 2023 01:14
@github-actions github-actions bot removed the 8.has: documentation This PR adds or changes documentation label Nov 9, 2023
@ShamrockLee ShamrockLee changed the title lib.applyToOverridable: init; refine the Overriding chapter of the Nixpkgs manual lib.applyToOverridable: init Nov 9, 2023
@ShamrockLee ShamrockLee force-pushed the lib-apply-to-overridable branch from 38fb7b6 to 1a0bf55 Compare November 14, 2023 15:49
@ShamrockLee ShamrockLee marked this pull request as ready for review November 14, 2023 16:23
@ShamrockLee
Copy link
Contributor Author

@ofborg build tests.overriding

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Nov 19, 2023

Inspecting deeper into the lib.extendDerivation, it came to me that simply adding a function like lib.applyToOverridable doesn't solve all the problem, as extendDerivation also changes the attributes of each derivation output. The issue needs to be fixed directly inside extendDerivation. Such fix would also address the TODO comments inside the implementation.

lib.applyToOverridable still has its use cases, but let's leave it to someone who really need it.

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: 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant