Merge pull request #40418 from oxij/lib/fix-module-aliases

lib, nixos: fix module aliases in presence of defaults
This commit is contained in:
Michael Raskin 2018-06-27 09:24:50 +00:00 committed by GitHub
commit b8ffd2459d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -532,9 +532,7 @@ rec {
# #
mkAliasDefinitions = mkAliasAndWrapDefinitions id; mkAliasDefinitions = mkAliasAndWrapDefinitions id;
mkAliasAndWrapDefinitions = wrap: option: mkAliasAndWrapDefinitions = wrap: option:
mkMerge mkIf (isOption option && option.isDefined) (wrap (mkMerge option.definitions));
(optional (isOption option && option.isDefined)
(wrap (mkMerge option.definitions)));
/* Compatibility. */ /* Compatibility. */
@ -669,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)
];
}; };
} }