oizys/lib/extended.nix

118 lines
2.9 KiB
Nix
Raw Normal View History

2024-07-25 09:57:26 -05:00
inputs: final: prev:
2024-05-06 14:32:00 -05:00
let
2024-08-11 08:29:46 -05:00
inherit (builtins)
listToAttrs
substring
filter
replaceStrings
;
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-08-11 08:29:46 -05:00
splitString
2024-05-06 14:32:00 -05:00
;
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-08-10 15:50:20 -05:00
2024-05-06 14:32:00 -05:00
enabled = {
enable = true;
};
disabled = {
enable = false;
};
2024-03-19 08:56:51 -05:00
2024-08-11 08:29:46 -05:00
# "opt1|opt2" |> pipeList -> ["opt1" "opt2"]
pipeList = s: s |> replaceStrings [ "\n" ] [ "|" ] |> splitString "|" |> filter (s': s' != "");
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-08-10 18:33:15 -05:00
isNixFile = p: p |> hasSuffix ".nix";
isDefaultNixFile = p: p |> hasSuffix "default.nix";
# filterNotDefaultNixFile = paths: filter (p: !(isDefaultNixFile p) && (isNixFile p)) paths;
2024-08-11 08:29:46 -05:00
filterNotDefaultNixFile = paths: paths |> filter (p: !(isDefaultNixFile p) && (isNixFile p));
2024-08-10 18:33:15 -05:00
# listNixFilesRecursive = dir: filterNotDefaultNixFile (listFilesRecursive dir);
2024-08-11 08:29:46 -05:00
listNixFilesRecursive = dir: dir |> listFilesRecursive |> filterNotDefaultNixFile;
2024-06-25 16:03:50 -05:00
2024-07-25 09:57:26 -05:00
# defaultLinuxPackage = flake: flake.packages.x86_64-linux.default;
# defaultPackageGeneric = system: flake: "${flake}.packages.${system}.default";
pkgsFromSystem = system: flake: inputs."${flake}".packages."${system}";
pkgFromSystem = system: flake: (pkgsFromSystem system flake).default;
2024-07-25 10:00:34 -05:00
overlayFrom = flake: inputs."${flake}".overlays.default;
2024-07-27 11:45:03 -05:00
flakeFromSystem = system: {
overlay = overlayFrom;
pkgs = pkgsFromSystem system;
pkg = pkgFromSystem system;
};
2024-08-10 15:50:20 -05:00
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-07-25 09:57:26 -05:00
pkgsFromSystem
pkgFromSystem
2024-07-25 10:00:34 -05:00
overlayFrom
2024-07-27 11:45:03 -05:00
flakeFromSystem
2024-08-11 08:29:46 -05:00
pipeList
2024-06-25 16:03:50 -05:00
;
2024-02-27 10:41:27 -06:00
}