From d1afc718f816dddaf22881c026d3163efa3e2470 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 1 May 2017 10:49:59 -0400 Subject: Add haskellPathsInDir lib function --- lib/filesystem.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/filesystem.nix') 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 ]; -- cgit v1.2.3