about summary refs log tree commit diff
path: root/read-tree.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-09T03·16+0000
committerVincent Ambo <tazjin@google.com>2019-12-09T03·16+0000
commitff38ae6c5f64ceadb307eac95bbe63e7a55f80c6 (patch)
treee7ce7d2b4b35b8696d5976187e945cf751797815 /read-tree.nix
parent7044424f52be19f79eb7eacbefa06b869a0dd9c3 (diff)
fix(read-tree): Don't import `default.nix` sibling expression r/105
If a folder contains a `default.nix`, Nix expressions contained in
adjacent files should not be imported (they might be things like a
`shell.nix` or a `deps.nix` which do not evaluate to derivations).

The tree traversal still continues for all children folders of a
folder with a `default.nix`.
Diffstat (limited to 'read-tree.nix')
-rw-r--r--read-tree.nix8
1 files changed, 5 insertions, 3 deletions
diff --git a/read-tree.nix b/read-tree.nix
index b2f161e885..2e182dfbde 100644
--- a/read-tree.nix
+++ b/read-tree.nix
@@ -72,10 +72,12 @@ let
     in listToAttrs (imported ++ dirs);
 
   importOr = path: dir: f:
-    let contents = f path (attrsToList dir);
+    let
+      allContents = f path (attrsToList dir);
+      dirOnlyContents = f path (filter (f: f.value == "directory") (attrsToList dir));
     in if dir ? "default.nix"
-      then import path (argsWithPath args (pathParts path)) // contents
-      else contents;
+      then import path (argsWithPath args (pathParts path)) // dirOnlyContents
+      else allContents;
 
   readTree = path: importOr path (readDir path) traverse;
 in readTree initPath