summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-03-19 17:22:39 +0100
committeraszlig <aszlig@redmoonstudios.org>2016-03-19 17:22:39 +0100
commit0f0805b51ad651f9f75e858edb77cf3a078f402d (patch)
treebb591cd95a2ae66e25eaf4d158077f52c21cf623 /lib/types.nix
parent3c060b93b6486e3e40b0709f507291135b9776a6 (diff)
lib/types: Handle submodules for type "either"
So far the "either" type only handled "flat" types, so you couldn't do something like: type = either int (submodule { options = ...; }); Not only caused this the submodule's options not being checked but also not show up in the documentation. This was something we stumbled on with #13916. Signed-off-by: aszlig <aszlig@redmoonstudios.org> Cc: @edolstra
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/types.nix b/lib/types.nix
index b4d29ac84d28..3495f34804cc 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -246,7 +246,25 @@ rec {
either = t1: t2: mkOptionType {
name = "${t1.name} or ${t2.name}";
check = x: t1.check x || t2.check x;
- merge = mergeOneOption;
+ merge = loc: defs:
+ if all t1.check (getValues defs) then t1.merge loc defs
+ else if all t2.check (getValues defs) then t2.merge loc defs
+ else throw ( "The option `${showOption loc}' has conflicting"
+ + " definitions for type either, in"
+ + " ${showFiles (getFiles defs)}.");
+
+ getSubOptions = prefix: t1.getSubOptions prefix
+ // t2.getSubOptions prefix;
+
+ getSubModules = concatLists (remove null [
+ t1.getSubModules
+ t2.getSubModules
+ ]);
+
+ substSubModules = m: let
+ maybeDef = def: r: if r == null then def else r;
+ in either (maybeDef t1 (t1.substSubModules m))
+ (maybeDef t2 (t2.substSubModules m));
};
# Obsolete alternative to configOf. It takes its option