1
0
mirror of https://git.oat.zone/dark-firepit/dotfiles synced 2024-11-26 06:08:48 +01:00
git.oat.zone--dark-firepit-.../lib/modules.nix

28 lines
1.0 KiB
Nix
Raw Normal View History

2022-01-11 18:44:40 +01:00
{ lib, ... }:
let
inherit (builtins) attrValues readDir pathExists;
inherit (lib) id filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix mapAttrs' trace fix fold isAttrs;
2022-01-11 18:44:40 +01:00
in rec {
mapModules' = dir: fn: dirfn:
filterAttrs
(name: type: type != null && !(hasPrefix "_" name))
(mapAttrs'
(name: type:
let path = "${toString dir}/${name}"; in
if type == "directory"
then nameValuePair name (dirfn path)
else if
type == "regular" &&
name != "default.nix" &&
hasSuffix ".nix" name
then nameValuePair (removeSuffix ".nix" name) (fn path)
else nameValuePair "" null
)
(readDir dir));
2022-01-11 18:44:40 +01:00
mapModules = dir: fn: mapModules' dir fn (path: if pathExists "${path}/default.nix" then fn path else null);
2022-01-11 18:44:40 +01:00
mapModulesRec = dir: fn: mapModules' dir fn (path: mapModulesRec path fn);
mapModulesRec' = dir: fn: fix (f: attrs: fold (x: xs: (if isAttrs x then f x else [x]) ++ xs) [] (attrValues attrs)) (mapModulesRec dir fn);
2022-01-11 18:44:40 +01:00
}