# Some of these functions were taken from https://github.com/NixOS/nixpkgs/blob/master/lib/ rec { hasSuffix = suffix: string: let lenSuffix = builtins.stringLength suffix; lenString = builtins.stringLength string; in ( lenString >= lenSuffix && (builtins.substring (lenString - lenSuffix) lenString string) == suffix ); recurseDir = dir: let dirContents = builtins.readDir dir; in (builtins.concatMap (dirItem: let itemType = builtins.getAttr dirItem dirContents; itemPath = dir + "/${dirItem}"; in if itemType == "directory" then (recurseDir itemPath) else [ itemPath ]) (builtins.attrNames dirContents)); recurseFilesInDir = dir: suffix: (builtins.filter (file: hasSuffix "${suffix}" file) (recurseDir dir)); recurseFilesInDirs = dirs: suffix: (builtins.concatMap (dir: (recurseFilesInDir dir "${suffix}")) dirs); }