mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
lib: add deprecated option warning helpers
This commit is contained in:
@@ -1,5 +1,47 @@
|
||||
{ lib }:
|
||||
{
|
||||
/*
|
||||
Builds a standard warning for an option value shape that is deprecated.
|
||||
|
||||
Example:
|
||||
mkDeprecatedOptionValueWarning {
|
||||
option = [ "programs" "example" "settings" ];
|
||||
old = "a list";
|
||||
replacement = "`programs.example.settings.items`";
|
||||
}
|
||||
|
||||
=> Using `programs.example.settings` as a list is deprecated and will be
|
||||
removed in a future release. Please use `programs.example.settings.items`
|
||||
instead.
|
||||
*/
|
||||
mkDeprecatedOptionValueWarning =
|
||||
{
|
||||
option,
|
||||
old,
|
||||
replacement,
|
||||
details ? "",
|
||||
}:
|
||||
''
|
||||
Using `${lib.showOption option}` as ${old} is deprecated and will be
|
||||
removed in a future release. Please use ${replacement} instead.
|
||||
''
|
||||
+ lib.optionalString (details != "") ''
|
||||
|
||||
${details}
|
||||
'';
|
||||
|
||||
# Builds a standard warning for an option value that has been renamed.
|
||||
mkDeprecatedOptionValueRenameWarning =
|
||||
{
|
||||
option,
|
||||
old,
|
||||
replacement,
|
||||
}:
|
||||
''
|
||||
The value ${old} for `${lib.showOption option}` is deprecated and will be
|
||||
removed in a future release. Please use ${replacement} instead.
|
||||
'';
|
||||
|
||||
/*
|
||||
Returns a function that maps
|
||||
[
|
||||
|
||||
@@ -177,6 +177,7 @@ import nmtSrc {
|
||||
(
|
||||
[
|
||||
# keep-sorted start case=no numeric=yes
|
||||
./lib/deprecations
|
||||
./lib/generators
|
||||
./lib/types
|
||||
./modules/files
|
||||
|
||||
3
tests/lib/deprecations/default.nix
Normal file
3
tests/lib/deprecations/default.nix
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
lib-deprecations-warnings = ./warnings.nix;
|
||||
}
|
||||
42
tests/lib/deprecations/warnings.nix
Normal file
42
tests/lib/deprecations/warnings.nix
Normal file
@@ -0,0 +1,42 @@
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
nmt.script =
|
||||
let
|
||||
expected = pkgs.writeText "deprecation-warnings.expected" ''
|
||||
Using `programs.example.settings` as a list is deprecated and will be
|
||||
removed in a future release. Please use `programs.example.settings.items` instead.
|
||||
|
||||
Move list entries under `settings.items`.
|
||||
|
||||
The value "kde6" for `qt.platformTheme.name` is deprecated and will be
|
||||
removed in a future release. Please use "kde" instead.
|
||||
'';
|
||||
|
||||
actual = pkgs.writeText "deprecation-warnings.actual" (
|
||||
lib.hm.deprecations.mkDeprecatedOptionValueWarning {
|
||||
option = [
|
||||
"programs"
|
||||
"example"
|
||||
"settings"
|
||||
];
|
||||
old = "a list";
|
||||
replacement = "`programs.example.settings.items`";
|
||||
details = "Move list entries under `settings.items`.";
|
||||
}
|
||||
+ "\n"
|
||||
+ lib.hm.deprecations.mkDeprecatedOptionValueRenameWarning {
|
||||
option = [
|
||||
"qt"
|
||||
"platformTheme"
|
||||
"name"
|
||||
];
|
||||
old = ''"kde6"'';
|
||||
replacement = ''"kde"'';
|
||||
}
|
||||
);
|
||||
in
|
||||
''
|
||||
assertFileContent ${actual} ${expected}
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user