Import all nix files in a directory tree. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic inputs

dont filter on root prefix. (#22)

for example, if user does `import-tree ./_foo`,

explicitly asking to traverse `./_foo`, then results must be
`./_foo/bar.nix` but not `./_foo/_baz.nix`.

that is, filtering occurs only on after-root paths.

authored by oeiuwq.com and committed by

GitHub a037ed2a 6ebb8cb8

+56 -2
+5
checkmate.nix
··· 255 255 ./tree/modules/hello-world/mod.nix 256 256 ]; 257 257 }; 258 + 259 + leafs."test loads from hidden directory but excludes sub-hidden" = { 260 + expr = lit.leafs ./tree/a/b/_c; 261 + expected = [ ./tree/a/b/_c/d/e.nix ]; 262 + }; 258 263 }; 259 264 260 265 }
+50 -2
default.nix
··· 27 27 }; 28 28 29 29 leafs = 30 - lib: root: 30 + lib: 31 31 let 32 32 treeFiles = t: (t.withLib lib).files; 33 + 33 34 listFilesRecursive = 34 35 x: 35 36 if isImportTree x then ··· 40 41 lib.filesystem.listFilesRecursive x 41 42 else 42 43 [ x ]; 44 + 43 45 nixFilter = andNot (lib.hasInfix "/_") (lib.hasSuffix ".nix"); 46 + 44 47 initialFilter = if initf != null then initf else nixFilter; 48 + 45 49 pathFilter = compose (and filterf initialFilter) toString; 50 + 46 51 otherFilter = and filterf (if initf != null then initf else (_: true)); 52 + 47 53 filter = x: if isPathLike x then pathFilter x else otherFilter x; 54 + 55 + isFileRelative = 56 + root: 57 + { file, rel }: 58 + if file != null && lib.hasPrefix root file then 59 + { 60 + file = null; 61 + rel = lib.removePrefix root file; 62 + } 63 + else 64 + { inherit file rel; }; 65 + getFileRelative = { file, rel }: if rel == null then file else rel; 66 + 67 + makeRelative = 68 + roots: 69 + lib.pipe roots [ 70 + (lib.lists.flatten) 71 + (builtins.filter isDirectory) 72 + (builtins.map builtins.toString) 73 + (builtins.map isFileRelative) 74 + (fx: fx ++ [ getFileRelative ]) 75 + ( 76 + fx: file: 77 + lib.pipe { 78 + file = builtins.toString file; 79 + rel = null; 80 + } fx 81 + ) 82 + ]; 83 + 84 + rootRelative = 85 + roots: 86 + let 87 + mkRel = makeRelative roots; 88 + in 89 + x: if isPathLike x then mkRel x else x; 48 90 in 91 + root: 49 92 lib.pipe 50 93 [ paths root ] 51 94 [ 52 95 (lib.lists.flatten) 53 96 (map listFilesRecursive) 54 97 (lib.lists.flatten) 55 - (builtins.filter filter) 98 + (builtins.filter ( 99 + compose filter (rootRelative [ 100 + paths 101 + root 102 + ]) 103 + )) 56 104 (map mapf) 57 105 ]; 58 106
+1
tree/a/b/_c/d/_f.nix
··· 1 + true