oizys/lib/extended.nix

90 lines
1.9 KiB
Nix
Raw Normal View History

2024-05-06 14:32:00 -05:00
final: prev:
let
2024-06-26 10:19:26 -05:00
inherit (builtins) listToAttrs substring filter;
2024-05-06 14:32:00 -05:00
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-26 10:19:26 -05:00
inherit (final.filesystem) listFilesRecursive;
2024-05-06 14:32:00 -05:00
in
2024-06-25 16:03:50 -05:00
let
2024-05-06 14:32:00 -05:00
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-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-06-25 16:03:50 -05:00
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-06-26 10:19:26 -05:00
2024-07-18 10:18:32 -05:00
flakeVer =
2024-07-18 11:46:02 -05:00
flake: "${flake.shortRev or flake.dirtyShortRev}-${mkDate (toString flake.lastModifiedDate)}";
2024-07-18 10:18:32 -05:00
2024-06-26 10:19:26 -05:00
isNixFile = p: hasSuffix ".nix" p;
isDefaultNixFile = p: hasSuffix "default.nix" p;
filterNotDefaultNixFile = paths: filter (p: !(isDefaultNixFile p) && (isNixFile p)) paths;
listNixFilesRecursive = dir: filterNotDefaultNixFile (listFilesRecursive dir);
2024-06-25 16:03:50 -05:00
in
{
inherit
enabled
disabled
enableAttrs
disableAttrs
mkOizysModule
mkDefaultOizysModule
mkDate
mkIfIn
2024-06-26 10:19:26 -05:00
isNixFile
listNixFilesRecursive
2024-07-18 10:18:32 -05:00
flakeVer
2024-06-25 16:03:50 -05:00
;
2024-02-27 10:41:27 -06:00
}