File tree Expand file tree Collapse file tree 3 files changed +56
-2
lines changed Expand file tree Collapse file tree 3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 255255 ./tree/modules/hello-world/mod.nix
256256 ] ;
257257 } ;
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+ } ;
258263 } ;
259264
260265 }
Original file line number Diff line number Diff line change 2727 } ;
2828
2929 leafs =
30- lib : root :
30+ lib :
3131 let
3232 treeFiles = t : ( t . withLib lib ) . files ;
33+
3334 listFilesRecursive =
3435 x :
3536 if isImportTree x then
4041 lib . filesystem . listFilesRecursive x
4142 else
4243 [ x ] ;
44+
4345 nixFilter = andNot ( lib . hasInfix "/_" ) ( lib . hasSuffix ".nix" ) ;
46+
4447 initialFilter = if initf != null then initf else nixFilter ;
48+
4549 pathFilter = compose ( and filterf initialFilter ) toString ;
50+
4651 otherFilter = and filterf ( if initf != null then initf else ( _ : true ) ) ;
52+
4753 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 ;
4890 in
91+ root :
4992 lib . pipe
5093 [ paths root ]
5194 [
5295 ( lib . lists . flatten )
5396 ( map listFilesRecursive )
5497 ( lib . lists . flatten )
55- ( builtins . filter filter )
98+ ( builtins . filter (
99+ compose filter ( rootRelative [
100+ paths
101+ root
102+ ] )
103+ ) )
56104 ( map mapf )
57105 ] ;
58106
Original file line number Diff line number Diff line change 1+ true
You can’t perform that action at this time.
0 commit comments