summaryrefslogtreecommitdiffstats
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2018-04-28 20:16:37 +0000
committerJan Malakhovski <oxij@oxij.org>2018-06-11 15:06:27 +0000
commit449d43fe01d9406d5fb74a687167dee316ec0ca9 (patch)
tree97e93ad48c460f73c653d08d62ee814f22f2ea56 /lib/modules.nix
parentc0c43e9c0767bb49a836d165f2b542a3e1334362 (diff)
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 = {}; }; }`.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 19e553bbc9b9..bb4a659e7a72 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -667,22 +667,26 @@ rec {
};
doRename = { from, to, visible, warn, use }:
+ { config, options, ... }:
let
+ fromOpt = getAttrFromPath from options;
+ toOpt = getAttrFromPath to options;
toOf = attrByPath to
(abort "Renaming error: option `${showOption to}' does not exist.");
in
- { config, options, ... }:
- { options = setAttrByPath from (mkOption {
- inherit visible;
- description = "Alias of <option>${showOption to}</option>.";
- apply = x: use (toOf config);
- });
- config = {
- warnings =
- let opt = getAttrFromPath from options; in
- optional (warn && opt.isDefined)
- "The option `${showOption from}' defined in ${showFiles opt.files} has been renamed to `${showOption to}'.";
- } // setAttrByPath to (mkAliasDefinitions (getAttrFromPath from options));
- };
+ {
+ options = setAttrByPath from (mkOption {
+ inherit visible;
+ description = "Alias of <option>${showOption to}</option>.";
+ apply = x: use (toOf config);
+ });
+ config = mkMerge [
+ {
+ warnings = optional (warn && fromOpt.isDefined)
+ "The option `${showOption from}' defined in ${showFiles fromOpt.files} has been renamed to `${showOption to}'.";
+ }
+ (mkAliasAndWrapDefinitions (setAttrByPath to) fromOpt)
+ ];
+ };
}