about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-19T15·33+0000
committerVincent Ambo <tazjin@google.com>2019-12-19T15·33+0000
commit467a66bac27e85b7e1fcd1b6ebf205481a8de8d6 (patch)
treea50f77c2e61c229646b907aee2e73777ab072984
parente996141d2ea24da382b8702e974f2b3baa5a6135 (diff)
feat(readTree): Add support for skipping directory subtrees r/203
Placing a special `.skip-subtree` file in any directory will now
prevent readTree from further traversing that part of the tree.

This makes it possible to have packages with internal Nix files that
are incompatible with the larger depot structure, for example for
projects like buildGo.nix which need to be compatible with the
external nixpkgs model.
-rw-r--r--read-tree.nix11
1 files changed, 9 insertions, 2 deletions
diff --git a/read-tree.nix b/read-tree.nix
index 2cdeb42aaa..82d5f040b2 100644
--- a/read-tree.nix
+++ b/read-tree.nix
@@ -5,6 +5,7 @@ let
     attrNames
     baseNameOf
     filter
+    hasAttr
     head
     length
     listToAttrs
@@ -35,9 +36,15 @@ let
       self = importWithMark path parts;
       joinChild = c: path + ("/" + c);
 
-      # Import non-empty subdirectories
+      # Import subdirectories of the current one, unless the special
+      # `.skip-subtree` file exists which makes readTree ignore the
+      # children.
+      #
+      # This file can optionally contain information on why the tree
+      # should be ignored, but its content is not inspected by
+      # readTree
       filterDir = f: dir."${f}" == "directory";
-      children = map (c: {
+      children = if hasAttr ".skip-subtree" dir then [] else map (c: {
         name = c;
         value = readTree (joinChild c) (parts ++ [ c ]);
       }) (filter filterDir (attrNames dir));