1 # Functions for copying sources to the Nix store.
12 A map of all haskell packages defined in the given path,
13 identified by having a cabal file with the same name as the
16 Type: Path -> Map String Path
19 # The directory within to search
21 let # Files in the root
22 root-files = builtins.attrNames (builtins.readDir root);
23 # Files with their full paths
24 root-files-with-paths =
26 { name = file; value = root + "/${file}"; }
28 # Subdirectories of the root with a cabal file.
30 builtins.filter ({ name, value }:
31 builtins.pathExists (value + "/${name}.cabal")
32 ) root-files-with-paths;
33 in builtins.listToAttrs cabal-subdirs;
35 Find the first directory containing a file matching 'pattern'
36 upward from a given 'file'.
37 Returns 'null' if no directories contain a file matching 'pattern'.
39 Type: RegExp -> Path -> Nullable { path : Path; matches : [ MatchResults ]; }
41 locateDominatingFile =
42 # The pattern to search for
44 # The file to start searching upward from
47 let files = builtins.attrNames (builtins.readDir path);
48 matches = builtins.filter (match: match != null)
49 (map (builtins.match pattern) files);
51 if builtins.length matches != 0
52 then { inherit path matches; }
58 let base = baseNameOf file;
59 type = (builtins.readDir parent).${base} or null;
60 in file == /. || type == "directory";
61 in go (if isDir then file else parent);
65 Given a directory, return a flattened list of all files within it recursively.
67 Type: Path -> [ Path ]
70 # The path to recursively list
72 lib.flatten (lib.mapAttrsToList (name: type:
73 if type == "directory" then
74 lib.filesystem.listFilesRecursive (dir + "/${name}")
77 ) (builtins.readDir dir));