3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #198450 from NixOS/doRename-no-warning

lib.modules.doRename: Don't define warning, even as undefined, if not warning.
This commit is contained in:
Silvan Mosberger 2022-11-03 13:51:16 +01:00 committed by GitHub
commit 011d767e1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View file

@ -1135,10 +1135,10 @@ rec {
type = toType;
});
config = mkMerge [
{
(optionalAttrs (options ? warnings) {
warnings = optional (warn && fromOpt.isDefined)
"The option `${showOption from}' defined in ${showFiles fromOpt.files} has been renamed to `${showOption to}'.";
}
})
(if withPriority
then mkAliasAndWrapDefsWithPriority (setAttrByPath to) fromOpt
else mkAliasAndWrapDefinitions (setAttrByPath to) fromOpt)

View file

@ -348,6 +348,13 @@ checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survive
# because of an `extendModules` bug, issue 168767.
checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
# doRename works when `warnings` does not exist.
checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
# doRename adds a warning.
checkConfigOutput '^"The option `a\.b. defined in `.*/doRename-warnings\.nix. has been renamed to `c\.d\.e.\."$' \
config.result \
./doRename-warnings.nix
cat <<EOF
====== module tests ======
$pass Pass

View file

@ -0,0 +1,11 @@
{ lib, ... }: {
imports = [
(lib.doRename { from = ["a" "b"]; to = ["c" "d" "e"]; warn = true; use = x: x; visible = true; })
];
options = {
c.d.e = lib.mkOption {};
};
config = {
a.b = 1234;
};
}

View file

@ -0,0 +1,14 @@
{ lib, config, ... }: {
imports = [
(lib.doRename { from = ["a" "b"]; to = ["c" "d" "e"]; warn = true; use = x: x; visible = true; })
];
options = {
warnings = lib.mkOption { type = lib.types.listOf lib.types.str; };
c.d.e = lib.mkOption {};
result = lib.mkOption {};
};
config = {
a.b = 1234;
result = lib.concatStringsSep "%" config.warnings;
};
}