summaryrefslogtreecommitdiff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2025-01-26 15:07:06 -0600
committerAlejandro Soto <alejandro@34project.org>2025-01-26 15:07:06 -0600
commit38c2e6d4c7bb4d78cf4c2069a7a22dac7ed00352 (patch)
treee48a712b675d25a6c36034ecb24de9910b7d2b85 /pkgs/lib
parentc4833e5ca8bbe6be6ab0f7880703d940423da6cc (diff)
flake: initial commit
Diffstat (limited to '')
-rw-r--r--pkgs/lib/default.nix3
-rw-r--r--pkgs/lib/importAll.nix20
2 files changed, 23 insertions, 0 deletions
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
new file mode 100644
index 0000000..e3ab56e
--- /dev/null
+++ b/pkgs/lib/default.nix
@@ -0,0 +1,3 @@
+{callPackage}: {
+ importAll = callPackage ./importAll.nix {};
+}
diff --git a/pkgs/lib/importAll.nix b/pkgs/lib/importAll.nix
new file mode 100644
index 0000000..6acabe9
--- /dev/null
+++ b/pkgs/lib/importAll.nix
@@ -0,0 +1,20 @@
+{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))