nvf/lib/config.nix
NotAShelf 56e20dd9c8
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
lib: format nixdoc values
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia6dcbf5c44ff6d29e5760111179341226a6a6964
2026-06-20 02:10:57 +03:00

86 lines
2.1 KiB
Nix

{lib}: let
inherit (lib.options) mkOption;
inherit (lib.types) bool;
inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
in {
/**
Build a boolean NixOS option with the given default value and description.
# Type
```
mkBool :: Bool -> String -> Option
```
# Arguments
- `value`: Default boolean value for the option.
- `description`: Documentation string for the option.
# Example
```nix
mkBool true "Enable feature X"
=> mkOption { type = bool; default = true; description = "Enable feature X"; }
```
*/
mkBool = value: description:
mkOption {
type = bool;
default = value;
inherit description;
};
/*
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 (
oldName: newNameOrNestedOpts:
if builtins.isAttrs newNameOrNestedOpts
then
genSetupOptRenames (oldSubpath ++ [oldName]) (newSubpath ++ [newNameOrNestedOpts._name or oldName])
(builtins.removeAttrs newNameOrNestedOpts ["_name"])
else
mkRenamedOptionModule
(oldBasePath ++ oldSubpath ++ [oldName])
(newBasePath ++ newSubpath ++ [newNameOrNestedOpts])
)
table;
in
flatten (genSetupOptRenames [] [] mappings);
}