From ba7197c271d54fd806970738e883b39c8ae1a3a9 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 2 Feb 2022 13:19:04 +0300 Subject: fix(nix/readTree): Use overrideAttrs with derivations Derivations that support overrideAttrs now have their readTree markers merged in using it, as passthru attributes. This makes the significant difference that overriding readTree targets using `overrideAttrs` keeps their readTree data intact. Change-Id: Ieef635f048781bf4782c1a28532b89a66d9ca24d Reviewed-on: https://cl.tvl.fyi/c/depot/+/5186 Tested-by: BuildkiteCI Reviewed-by: ezemtsov Autosubmit: tazjin --- nix/readTree/default.nix | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix index 0c59c890d4fa..22815a44c4ee 100644 --- a/nix/readTree/default.nix +++ b/nix/readTree/default.nix @@ -58,6 +58,17 @@ let __readTreeChildren = builtins.attrNames children; }; + # Merge two attribute sets, but place attributes in `passthru` via + # `overrideAttrs` for derivation targets that support it. + merge = a: b: + if a ? overrideAttrs + then + a.overrideAttrs + (prev: { + passthru = (prev.passthru or { }) // b; + }) + else a // b; + # Import a file and enforce our calling convention importFile = args: scopedArgs: path: parts: filter: let @@ -122,7 +133,7 @@ let name = c; value = if isAttrs imported - then imported // marker childParts { } + then merge imported (marker childParts { }) else imported; }) nixFiles; @@ -137,7 +148,7 @@ let in if isAttrs nodeValue - then nodeValue // allChildren // (marker parts allChildren) + then merge nodeValue (allChildren // (marker parts allChildren)) else nodeValue; # Function which can be used to find all readTree targets within an -- cgit 1.4.1