1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-29 03:21:21 +03:00
digga/lib/utils.nix

24 lines
685 B
Nix
Raw Normal View History

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