os/lib/utils.nix

50 lines
889 B
Nix
Raw Normal View History

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