2024-04-07 22:36:59 +00:00
|
|
|
{lib}: let
|
|
|
|
inherit (lib.options) mkOption;
|
|
|
|
inherit (lib.types) bool;
|
2024-04-20 12:59:46 +00:00
|
|
|
inherit (lib.modules) mkRenamedOptionModule;
|
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
inherit (lib.lists) flatten;
|
2024-04-07 22:36:59 +00:00
|
|
|
in {
|
|
|
|
mkBool = value: description:
|
|
|
|
mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = value;
|
|
|
|
inherit description;
|
|
|
|
};
|
2024-04-20 12:59:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Generates a list of mkRenamedOptionModule, from a mapping of the old name to
|
|
|
|
the new name. Nested options can optionally supply a "_name" to indicate its
|
|
|
|
new name.
|
|
|
|
|
|
|
|
# Example
|
|
|
|
|
|
|
|
```nix
|
|
|
|
batchRenameOptions ["nvimTree"] ["nvimTree" "setupOpts"] {
|
|
|
|
disableNetrw = "disable_netrw";
|
|
|
|
nestedOption = {
|
|
|
|
_name = "nested_option";
|
|
|
|
somethingElse = "something_else";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The above code is equivalent to this:
|
|
|
|
|
|
|
|
```nix
|
|
|
|
[
|
|
|
|
(
|
|
|
|
mkRenamedOptionModule
|
|
|
|
["nvimTree" "disableNetrw"]
|
|
|
|
["nvimTree" "setupOpts" "disable_netrw"]
|
|
|
|
)
|
|
|
|
(
|
|
|
|
mkRenamedOptionModule
|
|
|
|
["nvimTree" "nestedOption" "somethingElse"]
|
|
|
|
["nvimTree" "setupOpts" "nested_option" "something_else"]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
```
|
|
|
|
*/
|
|
|
|
batchRenameOptions = oldBasePath: newBasePath: mappings: let
|
|
|
|
genSetupOptRenames = oldSubpath: newSubpath: table:
|
|
|
|
mapAttrsToList (
|
2024-04-20 13:15:31 +00:00
|
|
|
oldName: newNameOrNestedOpts:
|
|
|
|
if builtins.isAttrs newNameOrNestedOpts
|
2024-04-20 12:59:46 +00:00
|
|
|
then
|
2024-04-20 13:15:31 +00:00
|
|
|
genSetupOptRenames (oldSubpath ++ [oldName]) (newSubpath ++ [newNameOrNestedOpts._name or oldName])
|
|
|
|
(builtins.removeAttrs newNameOrNestedOpts ["_name"])
|
2024-04-20 12:59:46 +00:00
|
|
|
else
|
|
|
|
mkRenamedOptionModule
|
|
|
|
(oldBasePath ++ oldSubpath ++ [oldName])
|
2024-04-20 13:15:31 +00:00
|
|
|
(newBasePath ++ newSubpath ++ [newNameOrNestedOpts])
|
2024-04-20 12:59:46 +00:00
|
|
|
)
|
|
|
|
table;
|
|
|
|
in
|
|
|
|
flatten (genSetupOptRenames [] [] mappings);
|
2024-04-07 22:36:59 +00:00
|
|
|
}
|