about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--default.nix3
-rw-r--r--nix/readTree/default.nix51
-rw-r--r--tools/rust-crates-advisory/default.nix5
3 files changed, 37 insertions, 22 deletions
diff --git a/default.nix b/default.nix
index 866b3fa6bfe9..941110b22200 100644
--- a/default.nix
+++ b/default.nix
@@ -79,13 +79,14 @@ let
       # Include the node itself if it is eligible.
       (if eligible node then [ node ] else [])
       # Include eligible children of the node
-      ++ concatMap gather (attrValues node)
+      ++ concatMap gather (map (attr: node."${attr}") node.__readTreeChildren)
       # Include specified sub-targets of the node
       ++ filter eligible (map
            (k: (node."${k}" or {}) // {
              # Keep the same tree location, but explicitly mark this
              # node as a subtarget.
              __readTree = node.__readTree;
+             __readTreeChildren = [];
              __subtarget = k;
            })
            (node.meta.targets or []))
diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix
index 5443d2edf539..68988424fb8c 100644
--- a/nix/readTree/default.nix
+++ b/nix/readTree/default.nix
@@ -47,26 +47,24 @@ let
       value = children.${name};
     }) names);
 
-  # Create a mark containing the location of this attribute.
-  marker = parts: {
+  # Create a mark containing the location of this attribute and
+  # a list of all child attribute names added by readTree.
+  marker = parts: children: {
     __readTree = parts;
+    __readTreeChildren = builtins.attrNames children;
   };
 
-  # The marker is added to every set that was imported directly by
-  # readTree.
-  importWithMark = args: scopedArgs: path: parts: filter:
+  # Import a file and enforce our calling convention
+  importFile = args: scopedArgs: path: parts: filter:
   let
       importedFile = if scopedArgs != {}
                      then builtins.scopedImport scopedArgs path
                      else import path;
       pathType = builtins.typeOf importedFile;
-      imported =
-        if pathType != "lambda"
-        then builtins.throw "readTree: trying to import ${toString path}, but it’s a ${pathType}, you need to make it a function like { depot, pkgs, ... }"
-        else importedFile (filter (argsWithPath args parts) parts);
-    in if (isAttrs imported)
-      then imported // (marker parts)
-      else imported;
+  in
+    if pathType != "lambda"
+    then builtins.throw "readTree: trying to import ${toString path}, but it’s a ${pathType}, you need to make it a function like { depot, pkgs, ... }"
+    else importedFile (filter (argsWithPath args parts) parts);
 
   nixFileName = file:
     let res = match "(.*)\\.nix" file;
@@ -79,7 +77,7 @@ let
 
       self = if rootDir
         then { __readTree = []; }
-        else importWithMark args scopedArgs initPath parts argsFilter;
+        else importFile args scopedArgs initPath parts argsFilter;
 
       # Import subdirectories of the current one, unless the special
       # `.skip-subtree` file exists which makes readTree ignore the
@@ -102,13 +100,30 @@ let
 
       # Import Nix files
       nixFiles = filter (f: f != null) (map nixFileName (attrNames dir));
-      nixChildren = map (c: let p = joinChild (c + ".nix"); in {
+      nixChildren = map (c: let
+        p = joinChild (c + ".nix");
+        childParts = parts ++ [ c ];
+        imported = importFile args scopedArgs p childParts argsFilter;
+      in {
         name = c;
-        value = importWithMark args scopedArgs p (parts ++ [ c ]) argsFilter;
+        value =
+          if isAttrs imported
+          then imported // marker parts {}
+          else imported;
       }) nixFiles;
-    in if dir ? "default.nix"
-      then (if isAttrs self then self // (listToAttrs children) else self)
-      else (listToAttrs (nixChildren ++ children) // (marker parts));
+
+      nodeValue = if dir ? "default.nix" then self else {};
+
+      allChildren = listToAttrs (
+        if dir ? "default.nix"
+        then children
+        else nixChildren ++ children
+      );
+
+    in
+      if isAttrs nodeValue
+      then nodeValue // allChildren // (marker parts allChildren)
+      else nodeValue;
 
 in {
   __functor = _:
diff --git a/tools/rust-crates-advisory/default.nix b/tools/rust-crates-advisory/default.nix
index d9b87839044b..1a26a523b22c 100644
--- a/tools/rust-crates-advisory/default.nix
+++ b/tools/rust-crates-advisory/default.nix
@@ -15,9 +15,8 @@ let
     sha256 = "0v086ybwr71zgs5nv8yr4w2w2d4daxx6in2s1sjb4m41q1r9p0wj";
   }}/crates";
 
-  our-crates = lib.mapAttrsToList (_: lib.id)
-    # this is a bit eh, but no idea how to avoid the readTree thing otherwise
-    (builtins.removeAttrs depot.third_party.rust-crates [ "__readTree" ]);
+  our-crates = lib.filter (v: v ? outPath)
+    (builtins.attrValues depot.third_party.rust-crates);
 
   check-security-advisory = depot.nix.writers.rustSimple {
     name = "parse-security-advisory";