dotfiles/checks/default.nix
magic_rb e99c9e848f
Support "splat" in checks
Signed-off-by: magic_rb <magic_rb@redalder.org>
2024-11-10 19:08:53 +01:00

52 lines
1,018 B
Nix

{
inputs,
lib,
...
}: let
inherit
(lib)
pipe
mapAttrs'
mapAttrs
filterAttrs
callPackageWith
hasSuffix
removeSuffix
nameValuePair
;
in {
perSystem = {
system,
pkgs,
...
}: let
importDefault = path:
import path {
inherit
lib
inputs
system
pkgs
;
};
in {
checks = pipe (builtins.readDir ./.) [
(filterAttrs (n: _: n != "default.nix"))
(mapAttrs (n: _: (importDefault (toString ./. + "/" + n))))
(mapAttrs' (n: v: let
newName =
if hasSuffix ".nix" n
then removeSuffix ".nix" n
else n;
in
nameValuePair newName v))
(filterAttrs (_: v: v ? "_type" && v._type == "if" -> v.condition))
(lib.mapAttrsToList nameValuePair)
(lib.foldl (acc: x:
if x.value ? "_type" && x.value._type == "splat"
then acc // x.value.value
else acc // {${x.name} = x.value;}) {})
];
};
}