diff options
author | Michael Raskin <7c6f434c@mail.ru> | 2018-06-27 09:24:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 09:24:50 +0000 |
commit | b8ffd2459d63a2acfd6a7918cb93f632f0af8455 (patch) | |
tree | 8419aff4e4b090bb8f66cd37a1cc251e78a74bc0 /lib | |
parent | 8d0d41da0905a7768df37060c6010f2dcdedf7fb (diff) | |
parent | 449d43fe01d9406d5fb74a687167dee316ec0ca9 (diff) | |
download | nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar.gz nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar.bz2 nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar.lz nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar.xz nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.tar.zst nixlib-b8ffd2459d63a2acfd6a7918cb93f632f0af8455.zip |
Merge pull request #40418 from oxij/lib/fix-module-aliases
lib, nixos: fix module aliases in presence of defaults
Diffstat (limited to 'lib')
-rw-r--r-- | lib/modules.nix | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 8baae4917053..bb4a659e7a72 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -532,9 +532,7 @@ rec { # mkAliasDefinitions = mkAliasAndWrapDefinitions id; mkAliasAndWrapDefinitions = wrap: option: - mkMerge - (optional (isOption option && option.isDefined) - (wrap (mkMerge option.definitions))); + mkIf (isOption option && option.isDefined) (wrap (mkMerge option.definitions)); /* Compatibility. */ @@ -669,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) + ]; + }; } |