Skip to content

readTree discards data thanks to calling overrideAttrs when merging #1

Description

@andrewhamon

If a readTree node is a derivation, readTree will always call overrideAttrs on it, which will silently discard information.

I think I understand the rationale for why readTree prefers overrideAttrs when available - it avoids inadvertently changing a derivation by merging arbitrary values on top of it, while it is much safer to leverage passthru which avoids any inadvertent cache-busting.

Unfortunately, this ends up causing some very non-intuitive behavior. Anything that is merged on top of a derivation using simple tools like // gets silently discarded, which can be very surprising.

For a contrived example, consider a readTree node that looks like this:

# customCowsay.nix
{ pkgs, ...}:
pkgs.cowsay // { hello = "here is a value that I am very explicitly merging on top"; }

Under readTree, if I try to reference customCowsay.hello, I will get an error that the attribute hello doesn't exist. How can that be? I most certainly added it! It takes a person well versed in nix, and willing to go hunting, to understand that this problem is that our value is getting transformed by calling overrideAttrs.

For a more concrete example, consider lib.hiPrio in nixpkgs. It sets meta.priority on an attrset using simple merging. So if we try to do something such as:

# customCowsay.nix
{ pkgs, ...}:
pkgs.lib.hiPrio pkgs.cowsay

Then the priority will be lost.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions