File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -101,8 +101,10 @@ The following is valid usage:
101
101
}
102
102
```
103
103
104
+ Other import-tree objects can also be given as arguments (or in lists) as if they were paths.
105
+
104
106
As an special case, when the single argument given to an ` import-tree ` object is an
105
- attribute-set * -it is _ NOT _ a path or list of paths- * , the ` import-tree ` object
107
+ attribute-set containing an ` options ` attribute , the ` import-tree ` object
106
108
assumes it is being evaluated as a module. This way, a pre-configured ` import-tree ` can
107
109
also be used directly in a list of module imports.
108
110
Original file line number Diff line number Diff line change 166
166
res . config . hello ;
167
167
expected = "world" ;
168
168
} ;
169
+
170
+ import-tree . "test can take other import-trees as if they were paths" = {
171
+ expr = ( lit . filter ( lib . hasInfix "mod" ) ) . leafs [
172
+ ( it . addPath ./tree/modules/hello-option )
173
+ ./tree/modules/hello-world
174
+ ] ;
175
+ expected = [
176
+ ./tree/modules/hello-option/mod.nix
177
+ ./tree/modules/hello-world/mod.nix
178
+ ] ;
179
+ } ;
169
180
} ;
170
181
171
182
}
Original file line number Diff line number Diff line change 29
29
lib : root :
30
30
let
31
31
initialFilter = andNot ( lib . hasInfix "/_" ) ( lib . hasSuffix ".nix" ) ;
32
+ listFilesRecursive = x : if isImportTree x then treeFiles x else lib . filesystem . listFilesRecursive x ;
33
+ treeFiles = t : ( t . withLib lib ) . leafs . result ;
32
34
in
33
35
lib . pipe
34
36
[ paths root ]
35
37
[
36
38
( lib . lists . flatten )
37
- ( map lib . filesystem . listFilesRecursive )
39
+ ( map listFilesRecursive )
38
40
( lib . lists . flatten )
39
41
( builtins . filter ( compose ( and filterf initialFilter ) toString ) )
40
42
( map mapf )
60
62
attrs : k : f :
61
63
attrs // { ${ k } = f attrs . ${ k } ; } ;
62
64
63
- functor =
64
- self : path :
65
- let
66
- imported-as-module = builtins . isAttrs path ;
67
- arg = if imported-as-module then [ ] else path ;
68
- in
69
- perform self . __config arg ;
65
+ isImportTree = and ( x : x ? __config . __functor ) builtins . isAttrs ;
66
+
67
+ inModuleEval = and ( x : x ? options ) builtins . isAttrs ;
68
+
69
+ functor = self : arg : perform self . __config ( if inModuleEval arg then [ ] else arg ) ;
70
70
71
71
callable =
72
72
let
You can’t perform that action at this time.
0 commit comments