-
Notifications
You must be signed in to change notification settings - Fork 6
/
lib.nix
39 lines (37 loc) · 936 Bytes
/
lib.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{ lib }:
rec {
kebabCaseToCamelCase = builtins.replaceStrings (map (s: "-${s}") lib.lowerChars) lib.upperChars;
listNixFilesRecursiveToAttrs =
dir:
lib.pipe dir [
lib.filesystem.listFilesRecursive
(builtins.filter (lib.hasSuffix ".nix"))
(builtins.filter (x: !lib.hasSuffix "interface.nix" x))
(map (value: {
name = lib.pipe value [
toString
(lib.removePrefix "${toString dir}/")
(lib.removeSuffix "/default.nix")
(lib.removeSuffix ".nix")
kebabCaseToCamelCase
(builtins.replaceStrings [ "/" ] [ "-" ])
];
inherit value;
}))
builtins.listToAttrs
];
modulesFromDir =
dir:
lib.pipe dir [
listNixFilesRecursiveToAttrs
(
modules:
modules
// {
default = {
imports = builtins.attrValues modules;
};
}
)
];
}