1
1
mirror of https://github.com/divnix/digga.git synced 2024-11-23 20:22:04 +03:00
digga/lib/utils.nix

52 lines
942 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);
vimport = path: name: import (path + "/${name}");
2019-12-15 11:08:22 +03:00
reqImport =
{ dir
, _import ? base: vimport dir (base + ".nix")
}:
mapFilterAttrs
(_: v: v != null)
(
n: v:
if
n != "default.nix"
&& hasSuffix ".nix" n
&& v == "regular"
2019-12-15 11:08:22 +03:00
then let
name = removeSuffix ".nix" n;
in
nameValuePair (name) (_import name)
2019-12-15 11:08:22 +03:00
else
nameValuePair ("") (null)
)
(readDir dir);
}