mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-09 03:56:04 +01:00
lib/deprecations: add mkSettingsRenamedOptionModules with transform parameter
Add a new library module for deprecation utilities with a configurable transformation function that allows specifying how option names should be converted (snake_case, kebab-case, etc.).
This commit is contained in:
parent
94d32062ca
commit
327885ceae
2 changed files with 51 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ rec {
|
||||||
assertions = import ./assertions.nix { inherit lib; };
|
assertions = import ./assertions.nix { inherit lib; };
|
||||||
|
|
||||||
booleans = import ./booleans.nix { inherit lib; };
|
booleans = import ./booleans.nix { inherit lib; };
|
||||||
|
deprecations = import ./deprecations.nix { inherit lib; };
|
||||||
generators = import ./generators.nix { inherit lib; };
|
generators = import ./generators.nix { inherit lib; };
|
||||||
gvariant = import ./gvariant.nix { inherit lib; };
|
gvariant = import ./gvariant.nix { inherit lib; };
|
||||||
maintainers = import ./maintainers.nix;
|
maintainers = import ./maintainers.nix;
|
||||||
|
|
|
||||||
50
modules/lib/deprecations.nix
Normal file
50
modules/lib/deprecations.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
{ lib }:
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Returns a function that maps
|
||||||
|
[
|
||||||
|
"someOption"
|
||||||
|
["fooBar" "someSubOption"]
|
||||||
|
{ old = "someOtherOption"; new = ["foo_bar" "some_other_option"]}
|
||||||
|
]
|
||||||
|
|
||||||
|
to
|
||||||
|
[
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
(oldPath ++ ["someOption"])
|
||||||
|
(newPath ++ ["some_option"])
|
||||||
|
)
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
(oldPath ++ ["fooBar" "someSubOption"])
|
||||||
|
(newPath ++ ["foo_bar" "some_sub_option"])
|
||||||
|
)
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
(oldPath ++ ["someOtherOption"])
|
||||||
|
(newPath ++ ["foo_bar" "some_other_option"])
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
The transform parameter is a function that takes a string and returns a string.
|
||||||
|
It is applied to each element of the old option path to generate the new option path.
|
||||||
|
Defaults to lib.hm.strings.toSnakeCase.
|
||||||
|
*/
|
||||||
|
mkSettingsRenamedOptionModules =
|
||||||
|
oldPrefix: newPrefix:
|
||||||
|
{
|
||||||
|
transform ? lib.hm.strings.toSnakeCase,
|
||||||
|
}:
|
||||||
|
map (
|
||||||
|
spec:
|
||||||
|
let
|
||||||
|
finalSpec =
|
||||||
|
if lib.isAttrs spec then
|
||||||
|
lib.mapAttrs (_: lib.toList) spec
|
||||||
|
else
|
||||||
|
{
|
||||||
|
old = lib.toList spec;
|
||||||
|
new = map transform finalSpec.old;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
lib.mkRenamedOptionModule (oldPrefix ++ finalSpec.old) (newPrefix ++ finalSpec.new)
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue