summary refs log tree commit diff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorBas van Dijk <v.dijk.bas@gmail.com>2018-08-07 18:34:38 +0200
committerSilvan Mosberger <contact@infinisil.com>2021-01-24 16:56:33 +0100
commitb454af298d0511f43564c5ba2c2b9576bffc025a (patch)
treed2539d71a3ad0e50bce8fb9b952a7033aaaab442 /lib/types.nix
parent5c7e19604efa1e325a34a04a410897bb5dde2efe (diff)
downloadnixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar.gz
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar.bz2
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar.lz
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar.xz
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.tar.zst
nixpkgs-b454af298d0511f43564c5ba2c2b9576bffc025a.zip
Revert "Remove types.functionTo."
This reverts commit 4ff1ab5a56f1280d2de319ad4eb4b2796e07ed35.

We need this to type options like:
services.xserver.windowManager.xmonad.extraPackages that specify functions that
take an attribute set containing packages / plugins and return a list containing
a selection of the values in this set.

The reason we need a dedicated type for this is to have the correct merge
behaviour. Without the functionTo type merging multiple function option
definitions results in an evaluation error. The functionTo type merges
definitions by returning a new function that applies the functions of all the
definitions to the given input and merges the result.

(cherry picked from commit 7ed41ff5e7e633dd64866398ee497ac02736a3a5)
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix
index ee891f8231b..0810a43ed0e 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -453,6 +453,16 @@ rec {
       functor = (defaultFunctor name) // { wrapped = elemType; };
     };
 
+    functionTo = elemType: mkOptionType {
+      name = "function that evaluates to a(n) ${elemType.name}";
+      check = isFunction;
+      merge = loc: defs:
+        fnArgs: elemType.merge loc (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs);
+      getSubOptions = elemType.getSubOptions;
+      getSubModules = elemType.getSubModules;
+      substSubModules = m: functionTo (elemType.substSubModules m);
+    };
+
     # A submodule (like typed attribute set). See NixOS manual.
     submodule = modules: submoduleWith {
       shorthandOnlyDefinesConfig = true;