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 <eugene.zemtsov@gmail.com>
Autosubmit: tazjin <tazjin@tvl.su>
This commit is contained in:
Vincent Ambo 2022-02-02 13:19:04 +03:00 committed by tazjin
parent 5540c80d87
commit ba7197c271

View file

@ -58,6 +58,17 @@ let
__readTreeChildren = builtins.attrNames children; __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 # Import a file and enforce our calling convention
importFile = args: scopedArgs: path: parts: filter: importFile = args: scopedArgs: path: parts: filter:
let let
@ -122,7 +133,7 @@ let
name = c; name = c;
value = value =
if isAttrs imported if isAttrs imported
then imported // marker childParts { } then merge imported (marker childParts { })
else imported; else imported;
}) })
nixFiles; nixFiles;
@ -137,7 +148,7 @@ let
in in
if isAttrs nodeValue if isAttrs nodeValue
then nodeValue // allChildren // (marker parts allChildren) then merge nodeValue (allChildren // (marker parts allChildren))
else nodeValue; else nodeValue;
# Function which can be used to find all readTree targets within an # Function which can be used to find all readTree targets within an