From 2141b4e38b8bae900b823b2cd1e2e59c5fa1368d Mon Sep 17 00:00:00 2001 From: Winter Date: Tue, 8 Jul 2025 17:05:16 -0400 Subject: [PATCH] lib.addMetaAttrs: use overrideAttrs when available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/meta.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/meta.nix b/lib/meta.nix index ee234d94489b..810b2d9a5e3e 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -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.