summaryrefslogtreecommitdiff
path: root/lib/importer.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/importer.nix')
-rw-r--r--lib/importer.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/importer.nix b/lib/importer.nix
new file mode 100644
index 0000000..d74d6c9
--- /dev/null
+++ b/lib/importer.nix
@@ -0,0 +1,15 @@
+lib: dir:
+let
+ nodes = builtins.readDir dir;
+
+ shouldImport =
+ name: type:
+ let
+ path = dir + "/${name}";
+ in
+ (type == "regular" && name != "default.nix" && lib.hasSuffix ".nix" name)
+ || (type == "directory" && builtins.pathExists (path + "/default.nix"));
+
+ validNodes = lib.filterAttrs shouldImport nodes;
+in
+map (name: dir + "/${name}") (builtins.attrNames validNodes)