diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-28 15:13:51 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-28 22:45:56 +0100 |
commit | c263b5b284cee4d2b658c6acd2942e367ac3f985 (patch) | |
tree | 0543aa1f4e574f1dd340384e0704ce73c71a5127 /lib/types.nix | |
parent | a40583e7e4eec305a08839df246455b0211dd7d1 (diff) |
Show error locations in submodules
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/types.nix b/lib/types.nix index dec9d82d6088..f459cda73cb5 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -37,6 +37,9 @@ rec { }; + addToPrefix = args: name: args // { prefix = args.prefix ++ [name]; }; + + types = rec { unspecified = mkOptionType { @@ -98,14 +101,15 @@ rec { listOf = elemType: mkOptionType { name = "list of ${elemType.name}s"; check = value: isList value && all elemType.check value; - merge = defs: map (def: elemType.merge [def]) (concatLists defs); + merge' = args: defs: imap (n: def: elemType.merge' (addToPrefix args (toString n)) [def]) (concatLists defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]); }; attrsOf = elemType: mkOptionType { name = "attribute set of ${elemType.name}s"; check = x: isAttrs x && all elemType.check (lib.attrValues x); - merge = lib.zipAttrsWith (name: elemType.merge' { inherit name; }); + merge' = args: lib.zipAttrsWith (name: + elemType.merge' (addToPrefix (args // { inherit name; }) name)); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]); }; @@ -128,7 +132,7 @@ rec { if isList x then listOnly.check x else if isAttrs x then attrOnly.check x else false; - merge = defs: attrOnly.merge (imap convertIfList defs); + merge' = args: defs: attrOnly.merge' args (imap convertIfList defs); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]); }; @@ -152,19 +156,19 @@ rec { nullOr = elemType: mkOptionType { name = "null or ${elemType.name}"; check = x: builtins.isNull x || elemType.check x; - merge = defs: + merge' = args: defs: if all isNull defs then null else if any isNull defs then throw "Some but not all values are null." - else elemType.merge defs; + else elemType.merge' args defs; getSubOptions = elemType.getSubOptions; }; functionTo = elemType: mkOptionType { name = "function that evaluates to a(n) ${elemType.name}"; check = builtins.isFunction; - merge = fns: - args: elemType.merge (map (fn: fn args) fns); + merge' = args: fns: + fnArgs: elemType.merge' args (map (fn: fn fnArgs) fns); getSubOptions = elemType.getSubOptions; }; @@ -173,13 +177,12 @@ rec { mkOptionType rec { name = "submodule"; check = x: isAttrs x || builtins.isFunction x; - # FIXME: make error messages include the parent attrpath. merge = merge' {}; merge' = args: defs: let coerce = def: if builtins.isFunction def then def else { config = def; }; modules = opts' ++ map coerce defs; - in (evalModules modules args).config; + in (evalModules' args.prefix modules args).config; getSubOptions = prefix: (evalModules' prefix opts' # FIXME: hack to get shit to evaluate. { name = ""; } |