summaryrefslogtreecommitdiff
path: root/pkgs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/default.nix4
-rw-r--r--pkgs/lib/importAll.nix17
2 files changed, 21 insertions, 0 deletions
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
new file mode 100644
index 0000000..a273758
--- /dev/null
+++ b/pkgs/lib/default.nix
@@ -0,0 +1,4 @@
+{ callPackage }:
+{
+ importAll = callPackage ./importAll.nix { };
+}
diff --git a/pkgs/lib/importAll.nix b/pkgs/lib/importAll.nix
new file mode 100644
index 0000000..30a1dd9
--- /dev/null
+++ b/pkgs/lib/importAll.nix
@@ -0,0 +1,17 @@
+{ lib }:
+{ root, exclude ? [ ] }:
+with builtins; with lib;
+
+# http://chriswarbo.net/projects/nixos/useful_hacks.html
+let
+ basename = removeSuffix ".nix";
+
+ isMatch = name: type: (hasSuffix ".nix" name || type == "directory")
+ && ! elem name (map basename exclude);
+
+ entry = name: _: {
+ name = basename name;
+ value = import (root + "/${name}");
+ };
+in
+mapAttrs' entry (filterAttrs isMatch (readDir root))