2019-12-14 07:30:43 +03:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
2020-07-31 00:29:58 +03:00
|
|
|
inherit (builtins) attrNames isAttrs readDir listToAttrs;
|
2019-12-14 07:30:43 +03:00
|
|
|
|
2020-01-04 08:06:31 +03:00
|
|
|
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
|
2019-12-14 07:30:43 +03:00
|
|
|
|
|
|
|
# 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);
|
2019-12-14 07:30:43 +03:00
|
|
|
|
2020-07-31 00:29:58 +03:00
|
|
|
# Generate an attribute set by mapping a function over a list of values.
|
|
|
|
genAttrs' = values: f: listToAttrs (map f values);
|
|
|
|
|
|
|
|
in {
|
|
|
|
inherit mapFilterAttrs genAttrs';
|
|
|
|
|
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"
|
2019-12-14 07:30:43 +03:00
|
|
|
|
2020-01-04 08:06:31 +03:00
|
|
|
then
|
|
|
|
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
|
2019-12-14 07:30:43 +03:00
|
|
|
|
2020-01-04 08:06:31 +03:00
|
|
|
else
|
|
|
|
nameValuePair ("") (null)) (readDir dir);
|
2020-07-31 00:29:58 +03:00
|
|
|
|
|
|
|
# Convert a list to file paths to attribute set
|
|
|
|
# that has the filenames stripped of nix extension as keys
|
|
|
|
# and imported content of the file as value.
|
|
|
|
pathsToImportedAttrs = paths:
|
|
|
|
genAttrs' paths (path: {
|
|
|
|
name = removeSuffix ".nix" (baseNameOf path);
|
|
|
|
value = import path;
|
|
|
|
});
|
|
|
|
|
2019-12-14 07:30:43 +03:00
|
|
|
}
|