From d7f29acd48f27f3ad0aa13b47c489f3d4bfda362 Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Mon, 22 Dec 2014 22:38:38 +0100 Subject: modules: Extract mkAliasDefinition from the rename.nix NixOS module. --- lib/modules.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/modules.nix b/lib/modules.nix index fdee8824493dd..d0b8f90e5ce67 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -356,6 +356,31 @@ rec { mkBefore = mkOrder 500; mkAfter = mkOrder 1500; + # Convenient property used to transfer all definitions and their + # properties from one option to another. This property is useful for + # renaming options, and also for including properties from another module + # system, including sub-modules. + # + # { config, options, ... }: + # + # { + # # 'bar' might not always be defined in the current module-set. + # config.foo.enable = mkAliasDefinitions (options.bar.enable or {}); + # + # # 'barbaz' has to be defined in the current module-set. + # config.foobar.paths = mkAliasDefinitions options.barbaz.paths; + # } + # + # Note, this is different than taking the value of the option and using it + # as a definition, as the new definition will not keep the mkOverride / + # mkDefault properties of the previous option. + # + mkAliasDefinitions = mkAliasAndWrapDefinitions id; + mkAliasAndWrapDefinitions = wrap: option: + mkMerge + (optional (isOption option && option.isDefined) + (wrap (mkMerge option.definitions))); + /* Compatibility. */ fixMergeModules = modules: args: evalModules { inherit modules args; check = false; }; -- cgit 1.4.1