summary refs log tree commit diff
path: root/lib/filesystem.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2017-05-01 10:49:59 -0400
committerShea Levy <shea@shealevy.com>2017-05-01 10:49:59 -0400
commitd1afc718f816dddaf22881c026d3163efa3e2470 (patch)
tree7fb08928f288dd53c24131519c51d6c480f4902a /lib/filesystem.nix
parenta53fb88d33917e052e7239392be67f10821713e2 (diff)
downloadnixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar.gz
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar.bz2
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar.lz
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar.xz
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.tar.zst
nixlib-d1afc718f816dddaf22881c026d3163efa3e2470.zip
Add haskellPathsInDir lib function
Diffstat (limited to 'lib/filesystem.nix')
-rw-r--r--lib/filesystem.nix20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/filesystem.nix b/lib/filesystem.nix
index 91b04d81c13b..3925beb21347 100644
--- a/lib/filesystem.nix
+++ b/lib/filesystem.nix
@@ -1,4 +1,22 @@
-{ # locateDominatingFile :  RegExp
+{ # haskellPathsInDir : Path -> Map String Path
+  # A map of all haskell packages defined in the given path,
+  # identified by having a cabal file with the same name as the
+  # directory itself.
+  haskellPathsInDir = root:
+    let # Files in the root
+        root-files = builtins.attrNames (builtins.readDir root);
+        # Files with their full paths
+        root-files-with-paths =
+          map (file:
+            { name = file; value = root + "/${file}"; }
+          ) root-files;
+        # Subdirectories of the root with a cabal file.
+        cabal-subdirs =
+          builtins.filter ({ name, value }:
+            builtins.pathExists (value + "/${name}.cabal")
+          ) root-files-with-paths;
+    in builtins.listToAttrs cabal-subdirs;
+  # locateDominatingFile :  RegExp
   #                      -> Path
   #                      -> Nullable { path : Path;
   #                                    matches : [ MatchResults ];