about summary refs log tree commit diff
path: root/nix/readTree
diff options
context:
space:
mode:
Diffstat (limited to 'nix/readTree')
-rw-r--r--nix/readTree/default.nix17
1 files changed, 17 insertions, 0 deletions
diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix
index 5e805b5f4a97..2ad8e40f6c28 100644
--- a/nix/readTree/default.nix
+++ b/nix/readTree/default.nix
@@ -157,6 +157,10 @@ let
            })
            (node.meta.targets or []))
     else [];
+
+  # Determine whether a given value is a derivation.
+  # Copied from nixpkgs/lib for cases where lib is not available yet.
+  isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
 in {
   inherit gather;
 
@@ -210,4 +214,17 @@ 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
+  # 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 {});
+  };
 }