Skip to content

lib.extendDerivation doesn't play with existing overriders of a package #288148

@ShamrockLee

Description

@ShamrockLee

Describe the bug

As a low-level approach to update Language-level derivations without affecting the value of its drvPath and outPath lib.extendDerivation has no idea about existing overriders (attributes that perform overriding) added by stdenv.mkDerivation or other build helpers. This causes surprising behaviors of per-output overriders and the effect of lib.extendDerivation lost after updating for derivations updated by lib.extendDerivation.

This has cause passthru value loss after overriding on several packages including the Linux kernel packages (#111504) and the python module packages made by buildPythonPackage or buildPythonApplication. The assertion added by lib.extendDerivation is also prone to loss after overriding.

Steps To Reproduce

Background:

nix-repl> pkgs.cowsay
«derivation /nix/store/snay6nazh182gnk10xkk8c0839p71m9k-cowsay-3.7.0.drv»

nix-repl> pkgs.cowsay.outputs
[ "out" "man" ]

Reproducer of the wrong behavior of <pkg>.<outputName>.overrideAttrs when <outputName> is not out after updated by lib.extendDerivation.

nix-repl> (pkgs.cowsay.man.overrideAttrs { }).outputName
"man"

nix-repl> (pkgs.cowsay.man.override { }).outputName
"man"

nix-repl> ((lib.extendDerivation true { } pkgs.cowsay).man.overrideAttrs { }).outputName
"out"

nix-repl> ((lib.extendDerivation true { } pkgs.cowsay).man.override { }).outputName
"out"

Reproducer of the loss of passthru values after overriding:

nix-repl> hello-with-ans = lib.extendDerivation true { ans = 42; } pkgs.hello
nix-repl> hello-with-ans.ans
42

nix-repl> (hello-with-ans.overrideAttrs { }).ans
error: attribute 'ans' missing

nix-repl> (hello-with-ans.override { }).ans
error: attribute 'ans' missing

Reproducer of the loss of assertions added by lib.extendDerivation after overriding:

nix-repl> hello-five = lib.extendDerivation (builtins.trace "2 + 2 != 5" false) { } pkgs.hello

nix-repl> hello-five
trace: 2 + 2 != 5
error: assertion 'condition' failed
«derivation

nix-repl> hello-five.overrideAttrs { }
«derivation /nix/store/hyljyc0pml0l1gxqmrxby45q8gwidxgd-hello-2.12.1.drv»

nix-repl> hello-five.override { }
«derivation /nix/store/hyljyc0pml0l1gxqmrxby45q8gwidxgd-hello-2.12.1.drv»

Expected behavior

nix-repl> ((lib.extendDerivation true { } pkgs.cowsay).man.overrideAttrs { }).outputName
"man"

nix-repl> ((lib.extendDerivation true { } pkgs.cowsay).man.override { }).outputName
"man"
nix-repl> (hello-with-ans.overrideAttrs { }).ans
42

nix-repl> (hello-with-ans.override { }).ans
42
nix-repl> hello-five.overrideAttrs { }
trace: 2 + 2 != 5
error: assertion 'condition' failed
«derivation

nix-repl> hello-five.override { }
trace: 2 + 2 != 5
error: assertion 'condition' failed
«derivation

Potential solutions/workarounds

  1. Fix this issue directly inside lib.extendDerivation: This would be tough, and would make the implementation much more complex and slower than the original one.
  2. Use the passthru attribute provided by stdenv.mkDerivation whenever applicable. One of the major application of lib.extendDerivation is to implement stdenv.mkDerivation, and the latter already provide a friendlier and more overridable interface (i.e. the passthru attribute) to pass attributes down to each outputs without drvAttrs. It should be suitable for most use cases when the assertion is not needed.
  3. Implement a lib.extendDerivation alternative that takes care of the overriders properly and re-apply the changes to future overriding results. lib.extendDerivation': init to fix overriding issues caused by lib.extendDerivation #269785 is one such attempt.

Screenshots

Additional context

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here

Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions