Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ The following is valid usage:
}
```

Other import-tree objects can also be given as arguments (or in lists) as if they were paths.

As an special case, when the single argument given to an `import-tree` object is an
attribute-set *-it is _NOT_ a path or list of paths-*, the `import-tree` object
attribute-set containing an `options` attribute, the `import-tree` object
assumes it is being evaluated as a module. This way, a pre-configured `import-tree` can
also be used directly in a list of module imports.

Expand Down
11 changes: 11 additions & 0 deletions checkmate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ in
res.config.hello;
expected = "world";
};

import-tree."test can take other import-trees as if they were paths" = {
expr = (lit.filter (lib.hasInfix "mod")).leafs [
(it.addPath ./tree/modules/hello-option)
./tree/modules/hello-world
];
expected = [
./tree/modules/hello-option/mod.nix
./tree/modules/hello-world/mod.nix
];
};
};

}
Expand Down
16 changes: 8 additions & 8 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ let
lib: root:
let
initialFilter = andNot (lib.hasInfix "/_") (lib.hasSuffix ".nix");
listFilesRecursive = x: if isImportTree x then treeFiles x else lib.filesystem.listFilesRecursive x;
treeFiles = t: (t.withLib lib).leafs.result;
in
lib.pipe
[ paths root ]
[
(lib.lists.flatten)
(map lib.filesystem.listFilesRecursive)
(map listFilesRecursive)
(lib.lists.flatten)
(builtins.filter (compose (and filterf initialFilter) toString))
(map mapf)
Expand All @@ -60,13 +62,11 @@ let
attrs: k: f:
attrs // { ${k} = f attrs.${k}; };

functor =
self: path:
let
imported-as-module = builtins.isAttrs path;
arg = if imported-as-module then [ ] else path;
in
perform self.__config arg;
isImportTree = and (x: x ? __config.__functor) builtins.isAttrs;

inModuleEval = and (x: x ? options) builtins.isAttrs;

functor = self: arg: perform self.__config (if inModuleEval arg then [ ] else arg);

callable =
let
Expand Down