mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-16 17:14:00 +00:00
lib: fix and simplify doRename
Before this change `mkRenamedOptionModule` would override option defaults even when the old option name is left unused. For instance ```nix { optios = { services.name.new = mkOption { default = { one = {}; }; }; }; imports = [ (mkRenamedOptionModule [ "services" "name" "old" ] [ "services" "name" "new" "two" ]) ]; config = {}; } ``` would evaluate to `{ config.services.name.new = { two = {}; }; }` when you'd expect it to evaluate to `{ config.services.name.new = { one = {}; }; }`.
This commit is contained in:
parent
c0c43e9c07
commit
449d43fe01
@ -667,22 +667,26 @@ rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
doRename = { from, to, visible, warn, use }:
|
doRename = { from, to, visible, warn, use }:
|
||||||
|
{ config, options, ... }:
|
||||||
let
|
let
|
||||||
|
fromOpt = getAttrFromPath from options;
|
||||||
|
toOpt = getAttrFromPath to options;
|
||||||
toOf = attrByPath to
|
toOf = attrByPath to
|
||||||
(abort "Renaming error: option `${showOption to}' does not exist.");
|
(abort "Renaming error: option `${showOption to}' does not exist.");
|
||||||
in
|
in
|
||||||
{ config, options, ... }:
|
{
|
||||||
{ options = setAttrByPath from (mkOption {
|
options = setAttrByPath from (mkOption {
|
||||||
inherit visible;
|
inherit visible;
|
||||||
description = "Alias of <option>${showOption to}</option>.";
|
description = "Alias of <option>${showOption to}</option>.";
|
||||||
apply = x: use (toOf config);
|
apply = x: use (toOf config);
|
||||||
});
|
});
|
||||||
config = {
|
config = mkMerge [
|
||||||
warnings =
|
{
|
||||||
let opt = getAttrFromPath from options; in
|
warnings = optional (warn && fromOpt.isDefined)
|
||||||
optional (warn && opt.isDefined)
|
"The option `${showOption from}' defined in ${showFiles fromOpt.files} has been renamed to `${showOption to}'.";
|
||||||
"The option `${showOption from}' defined in ${showFiles opt.files} has been renamed to `${showOption to}'.";
|
}
|
||||||
} // setAttrByPath to (mkAliasDefinitions (getAttrFromPath from options));
|
(mkAliasAndWrapDefinitions (setAttrByPath to) fromOpt)
|
||||||
};
|
];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user