summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorEric Sagnes <eric.sagnes@gmail.com>2016-09-24 21:10:29 +0900
committerEric Sagnes <eric.sagnes@gmail.com>2016-09-24 21:10:29 +0900
commit26ea947d330fef9624116ae100ff70101923de31 (patch)
tree2fdd8caae858851cf89c28e0df6c6d96efbd4c83 /lib/modules.nix
parent13eefc3a31c63febafec5107d38b60c8ddc3788e (diff)
downloadnixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar.gz
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar.bz2
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar.lz
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar.xz
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.tar.zst
nixpkgs-26ea947d330fef9624116ae100ff70101923de31.zip
lib/module: add mkChangedOptionModule function
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index d25a064ac8b..8db17c60579 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -598,6 +598,32 @@ rec {
                (mergeFn config)));
     };
 
+  /* Single "from" version of mkMergedOptionModule.
+     Return a module that causes a warning to be shown if the "from" option is
+     defined; the defined value can be used in the "mergeFn" to set the "to"
+     value.
+     This function can be used to change an option into another that has a
+     different type.
+
+     "mergeFn" takes the module "config" as a parameter and must return a value of
+     "to" option type.
+
+       mkChangedOptionModule [ "a" "b" "c" ] [ "x" "y" "z" ]
+         (config:
+           let value = getAttrFromPath [ "a" "b" "c" ] config;
+           in
+           if   value > 100 then "high"
+           else "normal")
+
+     - options.a.b.c is a removed int option
+     - options.x.y.z is a new str option that supersedes a.b.c
+
+     This show a warning if a.b.c is set, and set the value of x.y.z to the
+     result of the change function
+  */
+  mkChangedOptionModule = from: to: changeFn:
+    mkMergedOptionModule [ from ] to changeFn;
+
   /* Like ‘mkRenamedOptionModule’, but doesn't show a warning. */
   mkAliasOptionModule = from: to: doRename {
     inherit from to;