lib.addMetaAttrs: use overrideAttrs when available

Previously, any subsequent change to a derivation after
an `addMetaAttrs` call would cause said attribute(s) to
be unconditionally reset back to their previous value(s):

    nix-repl> ((oldPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
    error:
        … while evaluating the attribute 'meta.priority'
            at /nix/store/nxdiklm6dnf9pma1zg7srls2nzrykrjf-nixos/nixos/pkgs/stdenv/generic/make-derivation.nix:846:17:
            845|         inherit passthru overrideAttrs;
            846|         inherit meta;
                |                 ^
            847|       }

        error: attribute 'priority' missing
        at «string»:1:67:
                1| ((oldPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
                |                                                                   ^

This change makes it so that this does not happen (unless, of
course, a subsequent override does affect those values):

    nix-repl> ((newPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
    10

Fixes #323624.
This commit is contained in:
Winter
2025-07-08 17:05:16 -04:00
committed by Winter M
parent 30baf2b7f9
commit 2141b4e38b
+8 -1
View File
@@ -44,7 +44,14 @@ rec {
:::
*/
addMetaAttrs = newAttrs: drv: drv // { meta = (drv.meta or { }) // newAttrs; };
addMetaAttrs =
newAttrs: drv:
if drv ? overrideAttrs then
drv.overrideAttrs (old: {
meta = (old.meta or { }) // newAttrs;
})
else
drv // { meta = (drv.meta or { }) // newAttrs; };
/**
Disable Hydra builds of given derivation.