Skip to content

Commit

Permalink
Revert "Remove types.functionTo."
Browse files Browse the repository at this point in the history
This reverts commit 4ff1ab5.

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.
  • Loading branch information
basvandijk committed Aug 7, 2018
1 parent 25f4a12 commit 7ed41ff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/types.nix
Expand Up @@ -349,6 +349,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 = opts:
let
Expand Down

0 comments on commit 7ed41ff

Please sign in to comment.