git.iko.soy/typeable/nixpkgs
on master help sign in
lib/module: add mkChangedOptionModule function
commit26ea947d330fef9624116ae100ff70101923de31 authorEric Sagnes <eric.sagnes@gmail.com> dateSat 24 Sep 2016, 21:10 (10 years ago) parent13eefc3
1 file changed+26
lib/modules.nix+26
lib/modules.nix+26
@@ -598,6 +598,32 @@ rec {
598598 (mergeFn config)));
599599 };
600600
601+ /* Single "from" version of mkMergedOptionModule.
602+ Return a module that causes a warning to be shown if the "from" option is
603+ defined; the defined value can be used in the "mergeFn" to set the "to"
604+ value.
605+ This function can be used to change an option into another that has a
606+ different type.
607+
608+ "mergeFn" takes the module "config" as a parameter and must return a value of
609+ "to" option type.
610+
611+ mkChangedOptionModule [ "a" "b" "c" ] [ "x" "y" "z" ]
612+ (config:
613+ let value = getAttrFromPath [ "a" "b" "c" ] config;
614+ in
615+ if value > 100 then "high"
616+ else "normal")
617+
618+ - options.a.b.c is a removed int option
619+ - options.x.y.z is a new str option that supersedes a.b.c
620+
621+ This show a warning if a.b.c is set, and set the value of x.y.z to the
622+ result of the change function
623+ */
624+ mkChangedOptionModule = from: to: changeFn:
625+ mkMergedOptionModule [ from ] to changeFn;
626+
601627 /* Like ‘mkRenamedOptionModule’, but doesn't show a warning. */
602628 mkAliasOptionModule = from: to: doRename {
603629 inherit from to;