Skip to content

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

@ShamrockLee

Description

@ShamrockLee

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: libThe Nixpkgs function library
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions