2020-11-21 23:54:07 +03:00
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
inherit (builtins) attrNames isAttrs isInt readDir toJSON;
|
|
|
|
|
|
|
|
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
|
2020-12-23 19:54:51 +03:00
|
|
|
in
|
|
|
|
rec {
|
2020-11-21 23:54:07 +03:00
|
|
|
# mapFilterAttrs ::
|
|
|
|
# (name -> value -> bool )
|
|
|
|
# (name -> value -> { name = any; value = any; })
|
|
|
|
# attrs
|
|
|
|
mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f attrs);
|
|
|
|
|
|
|
|
recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
|
2020-12-23 19:54:51 +03:00
|
|
|
mapFilterAttrs (_: v: v != null)
|
|
|
|
(n: v:
|
|
|
|
if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
|
2020-11-21 23:54:07 +03:00
|
|
|
|
2020-12-23 19:54:51 +03:00
|
|
|
then
|
|
|
|
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
|
2020-11-21 23:54:07 +03:00
|
|
|
|
2020-12-23 19:54:51 +03:00
|
|
|
else
|
|
|
|
nameValuePair ("") (null))
|
|
|
|
(readDir dir);
|
2020-11-21 23:54:07 +03:00
|
|
|
|
|
|
|
pkgBin = name: "${pkgs."${name}"}/bin/${name}";
|
|
|
|
}
|