Created
January 13, 2020 18:57
-
-
Save worldofpeace/a4135fe79adb832ba08f8831853f92f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> {}; | |
with lib; | |
let | |
getDir = (dir: mapAttrs (file: type: | |
if type == "directory" | |
then getDir "${dir}/${file}" | |
else type) | |
(builtins.readDir dir)); | |
dirFiles = | |
dir: collect isString | |
(mapAttrsRecursive | |
(path: type: concatStringsSep "/" path) | |
(getDir dir)); | |
allFiles = | |
dir: collect isString | |
(mapAttrsRecursive | |
(path: type: concatStringsSep "/" path) | |
(getDir dir)); | |
matchFile = regexp: file: | |
null != (builtins.match regexp file); | |
anyMatchForFile = regexps: file: | |
builtins.all (regexp: !(matchFile regexp file)) regexps; | |
filteredFiles = regexps: dir: | |
map (file: dir + "/${file}") | |
(filter (file: anyMatchForFile regexps file) (allFiles dir)); | |
filteredModules = regexps: dir: | |
map (file: import file) (filteredFiles regexps dir); | |
recImport = dir: | |
map (file: dir + "/${file}") | |
(filter (file: | |
((hasSuffix ".nix" file) && (!(hasSuffix ".lib.nix" file)) && (file != "default.nix"))) | |
(dirFiles dir)); | |
recCallPackage = dir: | |
let content = builtins.readDir dir; in | |
builtins.listToAttrs | |
(map (n: {name = n; value = callPackage (dir + ("/" + n)) {}; }) | |
(builtins.filter (n: builtins.pathExists (dir + ("/" + n + "/default.nix"))) | |
(builtins.attrNames content))); | |
in { | |
inherit getDir dirFiles allFiles matchFile anyMatchForFile | |
filteredFiles filteredModules recImport recCallPackage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment