diff options
author | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2015-01-01 06:59:42 -0800 |
---|---|---|
committer | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2015-01-01 06:59:42 -0800 |
commit | 816229593a521e420f5ce7b9f7e8f183aabb390c (patch) | |
tree | 92781572fd876556837956d9760e29a69ac2a08e | |
parent | 1d835a2cbdd64e7b257c513904be9d17706c38e9 (diff) | |
parent | d7f29acd48f27f3ad0aa13b47c489f3d4bfda362 (diff) | |
download | nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar.gz nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar.bz2 nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar.lz nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar.xz nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.tar.zst nixlib-816229593a521e420f5ce7b9f7e8f183aabb390c.zip |
Merge pull request #5441 from nbp/mkAlias
modules: Extract mkAliasDefinition from the rename.nix NixOS module.
-rw-r--r-- | lib/modules.nix | 25 | ||||
-rw-r--r-- | nixos/modules/rename.nix | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index fdee8824493d..d0b8f90e5ce6 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; }; diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index cb1b92e78d62..20fd76855d96 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -55,8 +55,8 @@ let apply = x: use (toOf config); inherit visible; }); - } - { config = setTo (mkMerge (if (fromOf options).isDefined then [ (define (mkMerge (fromOf options).definitions)) ] else [])); + + config = setTo (mkAliasAndWrapDefinitions define (fromOf options)); } ]; |