Skip to content

Commit 7a0649e

Browse files
authored
fix: dont try to convert attrSets that are not paths. (#16)
1 parent e6603e9 commit 7a0649e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

checkmate.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ in
203203
expected = [ ./tree/modules/hello-world/mod.nix ];
204204
};
205205

206+
import-tree."test passes non-paths without string conversion" = {
207+
expr =
208+
let
209+
mod = it [
210+
{
211+
options.hello = lib.mkOption {
212+
default = "world";
213+
type = lib.types.str;
214+
};
215+
}
216+
];
217+
res = lib.modules.evalModules { modules = [ mod ]; };
218+
in
219+
res.config.hello;
220+
expected = "world";
221+
};
222+
206223
import-tree."test can take other import-trees as if they were paths" = {
207224
expr = (lit.filter (lib.hasInfix "mod")).leafs [
208225
(it.addPath ./tree/modules/hello-option)

default.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ let
3535
treeFiles x
3636
else if hasOutPath x then
3737
listFilesRecursive x.outPath
38-
else if lib.pathIsDirectory x then
38+
else if isDirectory x then
3939
lib.filesystem.listFilesRecursive x
4040
else
4141
[ x ];
4242
treeFiles = t: (t.withLib lib).leafs.result;
43+
pathFilter = compose (and filterf initialFilter) toString;
44+
filter = x: if isPathLike x then pathFilter x else filterf x;
4345
in
4446
lib.pipe
4547
[ paths root ]
4648
[
4749
(lib.lists.flatten)
4850
(map listFilesRecursive)
4951
(lib.lists.flatten)
50-
(builtins.filter (compose (and filterf initialFilter) toString))
52+
(builtins.filter filter)
5153
(map mapf)
5254
];
5355

@@ -71,6 +73,10 @@ let
7173
attrs: k: f:
7274
attrs // { ${k} = f attrs.${k}; };
7375

76+
isDirectory = and (x: builtins.readFileType x == "directory") isPathLike;
77+
78+
isPathLike = x: builtins.isPath x || builtins.isString x || hasOutPath x;
79+
7480
hasOutPath = and (x: x ? outPath) builtins.isAttrs;
7581

7682
isImportTree = and (x: x ? __config.__functor) builtins.isAttrs;

0 commit comments

Comments
 (0)