Description
lib.customisation.makeOverridable not only adds a new overrider override to the result set, but also takes care of existing overriders overrideAttrs and overrideDerivation, ensuring that they works together with the added override.
However, it doesn't take into account some other potentially existing overriders, such as overrideScope and extend, causing the override result of overrideScope and extend to lose the override attribute.
Reproduction steps
Reproduction with nix repl at the nixpkgs project root:
nix-repl> lib = import ./lib
nix-repl> pkgs = import ./. { }
nix-repl> scope = lib.makeOverridable ({ lib }: lib.makeScope lib.callPackageWith (final: { a = 1; b = 2; })) { inherit lib; }
nix-repl> scope
{
a = 1;
b = 2;
callPackage = «lambda callPackageWith @ /path/to/nixpkgs/lib/customisation.nix:386:15»;
newScope = «lambda newScope @ /path/to/nixpkgs/lib/customisation.nix:745:20»;
override = { ... };
overrideDerivation = «lambda overrideDerivation @ /path/to/nixpkgs/lib/customisation.nix:313:32»;
overrideScope = «lambda overrideScope @ /path/to/nixpkgs/lib/customisation.nix:747:25»;
packages = «lambda @ «string»:1:67»;
}
nix-repl> scope.override
{
__functionArgs = { ... };
__functor = «lambda __functor @ /path/to/nixpkgs/lib/trivial.nix:1009:17»;
}
nix-repl> scope.overrideScope
«lambda overrideScope @ /path/to/nixpkgs/lib/customisation.nix:747:25»
nix-repl> scope' = scope.overrideScope (final: previous: { c = final.a + final.b; })
nix-repl> scope'
{
a = 1;
b = 2;
c = 3;
callPackage = «lambda callPackageWith @ /path/to/nixpkgs/lib/customisation.nix:386:15»;
newScope = «lambda newScope @ /path/to/nixpkgs/lib/customisation.nix:745:20»;
overrideScope = «lambda overrideScope @ /path/to/nixpkgs/lib/customisation.nix:747:25»;
packages = «lambda extends @ /path/to/nixpkgs/lib/fixed-points.nix:323:7»;
}
nix-repl> scope'.overrideScope
«lambda overrideScope @ /path/to/nixpkgs/lib/customisation.nix:747:25»
nix-repl> scope'.override
error: attribute 'override' missing
at «string»:1:1:
1| scope'.override
| ^
Additional context
@LunNova discovered this bug when working on PR #445668. See the comment for detail: #445668 (comment)
Description
lib.customisation.makeOverridablenot only adds a new overrideroverrideto the result set, but also takes care of existing overridersoverrideAttrsandoverrideDerivation, ensuring that they works together with the addedoverride.However, it doesn't take into account some other potentially existing overriders, such as
overrideScopeandextend, causing the override result ofoverrideScopeandextendto lose theoverrideattribute.Reproduction steps
Reproduction with
nix replat the nixpkgs project root:Additional context
@LunNova discovered this bug when working on PR #445668. See the comment for detail: #445668 (comment)