summaryrefslogtreecommitdiff
path: root/doctrine/lib/importAll.nix
blob: 6acabe9f9b563bb831c27d54dc6869eaa4c36f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{lib}: {
  root,
  exclude ? [],
}:
with builtins;
with lib;
# http://chriswarbo.net/projects/nixos/useful_hacks.html
  let
    basename = removeSuffix ".nix";

    isMatch = name: type:
      (hasSuffix ".nix" name || type == "directory")
      && ! elem name (map basename exclude);

    entry = name: _: {
      name = basename name;
      value = import (root + "/${name}");
    };
  in
    mapAttrs' entry (filterAttrs isMatch (readDir root))