about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-02-07T10·46+0300
committertazjin <tazjin@tvl.su>2022-02-07T15·13+0000
commit8b8c98380e85b2057a3c35ce3d76879fab4266b0 (patch)
treeeccb180e2f6f13d1af58f8822a39ce2f523cd4aa /nix
parent3bde42586089a28a49dc063c2e639194211cb9af (diff)
refactor(readTree): deprecate meta.targets for meta.ci.targets r/3775
This means that we use the meta.ci attribute more consistently.

The meta.targets attribute is still read, but prints a big, red
warning telling people to migrate to the new one.

Fixes b/176

Change-Id: Ifb4452f529cfc6bbd5018ad7374cac1c83b10045
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5238
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'nix')
-rw-r--r--nix/readTree/default.nix40
1 files changed, 30 insertions, 10 deletions
diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix
index 5d2e1fff6a..ba3363d8d6 100644
--- a/nix/readTree/default.nix
+++ b/nix/readTree/default.nix
@@ -158,12 +158,27 @@ let
     then merge nodeValue (allChildren // (marker parts allChildren))
     else nodeValue;
 
+  # Helper function to fetch subtargets from a target. This is a
+  # temporary helper to warn on the use of the `meta.targets`
+  # attribute, which is deprecated in favour of `meta.ci.targets`.
+  subtargets = node:
+    let targets = (node.meta.targets or [ ]) ++ (node.meta.ci.targets or [ ]);
+    in if node ? meta.targets then
+      builtins.trace ''
+        Warning: The meta.targets attribute is deprecated.
+
+        Please move the subtargets of //${mkLabel node} to the
+        meta.ci.targets attribute.
+        
+      ''
+        targets else targets;
+
   # Function which can be used to find all readTree targets within an
   # attribute set.
   #
   # This function will gather physical targets, that is targets which
   # correspond directly to a location in the repository, as well as
-  # subtargets (specified in the meta.targets attribute of a node).
+  # subtargets (specified in the meta.ci.targets attribute of a node).
   #
   # This can be used to discover targets for inclusion in CI
   # pipelines.
@@ -187,7 +202,7 @@ let
           __readTreeChildren = [ ];
           __subtarget = k;
         })
-        (node.meta.targets or [ ]))
+        (subtargets node))
     else [ ];
 
   # Determine whether a given value is a derivation.
@@ -249,16 +264,21 @@ in
   # It is often required to create the args attribute set.
   fix = f: let x = f x; in x;
 
-  # Takes an attribute set and adds a meta.targets attribute to it
+  # Takes an attribute set and adds a meta.ci.targets attribute to it
   # which contains all direct children of the attribute set which are
   # derivations.
   #
   # Type: attrs -> attrs
-  drvTargets = attrs: attrs // {
-    meta = {
-      targets = builtins.filter
-        (x: isDerivation attrs."${x}")
-        (builtins.attrNames attrs);
-    } // (attrs.meta or { });
-  };
+  drvTargets = attrs:
+    attrs // {
+      # preserve .meta from original attrs
+      meta = (attrs.meta or { }) // {
+        # preserve .meta.ci (except .targets) from original attrs
+        ci = (attrs.meta.ci or { }) // {
+          targets = builtins.filter
+            (x: isDerivation attrs."${x}")
+            (builtins.attrNames attrs);
+        };
+      };
+    };
 }