plugins/by-name: init

Add support for automatically importing any directories under
`plugins/by-name`.

Includes a validation test, which is run by CI and by the pre-commit hook.
This commit is contained in:
Matt Sturgeon 2024-09-04 16:22:17 +01:00
parent 6df273540c
commit faff32b9f1
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
5 changed files with 186 additions and 9 deletions

View file

@ -1,4 +1,17 @@
{ ... }:
{ lib, ... }:
let
inherit (builtins) readDir pathExists;
inherit (lib.attrsets) foldlAttrs;
inherit (lib.lists) optional optionals;
by-name = ../plugins/by-name;
in
{
imports = [ ../plugins/default.nix ];
imports =
[ ../plugins ]
++ optionals (pathExists by-name) (
foldlAttrs (
prev: name: type:
prev ++ optional (type == "directory") (by-name + "/${name}")
) [ ] (readDir by-name)
);
}