git.iko.soy/typeable/nixpkgs
on master help sign in
modules: Extract mkAliasDefinition from the rename.nix NixOS module.
commitd7f29acd48f27f3ad0aa13b47c489f3d4bfda362 authorNicolas B. Pierron <nicolas.b.pierron@gmail.com> dateMon 22 Dec 2014, 22:38 (12 years ago) parent4e55873
2 files changed+27−2
lib/modules.nix+25 nixos/modules/rename.nix+2−2
lib/modules.nix+25
@@ -356,6 +356,31 @@ rec {
356356 mkBefore = mkOrder 500;
357357 mkAfter = mkOrder 1500;
358358
359+ # Convenient property used to transfer all definitions and their
360+ # properties from one option to another. This property is useful for
361+ # renaming options, and also for including properties from another module
362+ # system, including sub-modules.
363+ #
364+ # { config, options, ... }:
365+ #
366+ # {
367+ # # 'bar' might not always be defined in the current module-set.
368+ # config.foo.enable = mkAliasDefinitions (options.bar.enable or {});
369+ #
370+ # # 'barbaz' has to be defined in the current module-set.
371+ # config.foobar.paths = mkAliasDefinitions options.barbaz.paths;
372+ # }
373+ #
374+ # Note, this is different than taking the value of the option and using it
375+ # as a definition, as the new definition will not keep the mkOverride /
376+ # mkDefault properties of the previous option.
377+ #
378+ mkAliasDefinitions = mkAliasAndWrapDefinitions id;
379+ mkAliasAndWrapDefinitions = wrap: option:
380+ mkMerge
381+ (optional (isOption option && option.isDefined)
382+ (wrap (mkMerge option.definitions)));
383+
359384
360385 /* Compatibility. */
361386 fixMergeModules = modules: args: evalModules { inherit modules args; check = false; };
nixos/modules/rename.nix+2−2
@@ -55,8 +55,8 @@ let
5555 apply = x: use (toOf config);
5656 inherit visible;
5757 });
58− }
59− { config = setTo (mkMerge (if (fromOf options).isDefined then [ (define (mkMerge (fromOf options).definitions)) ] else []));
58+
59+ config = setTo (mkAliasAndWrapDefinitions define (fromOf options));
6060 }
6161 ];
6262