oizys/lib/extended.nix

54 lines
1.1 KiB
Nix
Raw Permalink Normal View History

2024-05-06 14:32:00 -05:00
final: prev:
let
inherit (final)
hasSuffix
mkEnableOption
mkIf
mkOption
types
;
in
rec {
enabled = {
enable = true;
};
disabled = {
enable = false;
};
2024-03-19 08:56:51 -05:00
2024-03-19 08:54:11 -05:00
# ["a" "b"] -> {a.enable = true; b.enable = true;}
2024-05-06 14:32:00 -05:00
enableAttrs =
attrs:
builtins.listToAttrs (
map (attr: {
2024-03-19 08:56:51 -05:00
name = attr;
value = enabled;
2024-05-06 14:32:00 -05:00
}) attrs
);
2024-03-19 08:54:11 -05:00
# ["a" "b"] -> {a.enable = false; b.enable = false;}
2024-05-06 14:32:00 -05:00
disableAttrs =
attrs:
builtins.listToAttrs (
map (attr: {
2024-03-19 08:56:51 -05:00
name = attr;
value = disabled;
2024-05-06 14:32:00 -05:00
}) attrs
);
2024-03-19 08:54:11 -05:00
2024-03-01 00:26:52 -06:00
isNixFile = path: hasSuffix ".nix" path;
2024-02-27 10:41:27 -06:00
mkIfIn = name: list: prev.mkIf (builtins.elem name list);
2024-03-21 10:53:27 -05:00
mkOizysModule = config: attr: content: {
options.oizys.${attr}.enable = mkEnableOption "enable ${attr} support";
config = mkIf config.oizys.${attr}.enable content;
};
2024-03-21 15:48:48 -05:00
mkDefaultOizysModule = config: attr: content: {
options.oizys.${attr}.enable = mkOption {
default = true;
description = "enable ${attr} support";
type = types.bool;
};
config = mkIf config.oizys.${attr}.enable content;
};
2024-02-27 10:41:27 -06:00
}