2019-12-14 05:30:43 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
2020-01-04 06:06:31 +01:00
|
|
|
inherit (builtins) attrNames isAttrs readDir;
|
2019-12-14 05:30:43 +01:00
|
|
|
|
2020-01-04 06:06:31 +01:00
|
|
|
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
|
2019-12-14 05:30:43 +01:00
|
|
|
|
2020-01-04 06:06:31 +01:00
|
|
|
in rec {
|
2019-12-14 05:30:43 +01:00
|
|
|
# mapFilterAttrs ::
|
|
|
|
# (name -> value -> bool )
|
|
|
|
# (name -> value -> { name = any; value = any; })
|
|
|
|
# attrs
|
2020-01-04 06:06:31 +01:00
|
|
|
mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f attrs);
|
2019-12-14 05:30:43 +01:00
|
|
|
|
2020-01-04 06:06:31 +01:00
|
|
|
recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
|
|
|
|
mapFilterAttrs (_: v: v != null) (n: v:
|
|
|
|
if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
|
2019-12-14 05:30:43 +01:00
|
|
|
|
2020-01-04 06:06:31 +01:00
|
|
|
then
|
|
|
|
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
|
2019-12-14 05:30:43 +01:00
|
|
|
|
2020-01-04 06:06:31 +01:00
|
|
|
else
|
|
|
|
nameValuePair ("") (null)) (readDir dir);
|
2019-12-14 05:30:43 +01:00
|
|
|
}
|