oizys/lib/extended.nix

65 lines
1.3 KiB
Nix
Raw Normal View History

2024-05-06 14:32:00 -05:00
final: prev:
let
inherit (final)
2024-06-18 10:13:24 -05:00
concatStringsSep
2024-05-06 14:32:00 -05:00
hasSuffix
mkEnableOption
mkIf
mkOption
types
;
2024-06-18 10:13:24 -05:00
inherit (builtins) listToAttrs substring;
2024-05-06 14:32:00 -05:00
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:
2024-06-18 10:13:24 -05:00
listToAttrs (
2024-05-06 14:32:00 -05:00
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:
2024-06-18 10:13:24 -05:00
listToAttrs (
2024-05-06 14:32:00 -05:00
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-06-18 10:13:24 -05:00
# generate date string with '-' from long date
mkDate =
longDate:
(concatStringsSep "-" [
(substring 0 4 longDate)
(substring 4 2 longDate)
(substring 6 2 longDate)
]);
2024-02-27 10:41:27 -06:00
}