summaryrefslogtreecommitdiff
path: root/doctrine/lib/import-all.nix
blob: 423dd9c92c25a06588b19e22c4b6b9c738958a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
  lib,
  root,
  exclude ? ["default"],
}:
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 (basename name) exclude;

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