diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-30 14:21:41 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-30 14:57:43 +0100 |
commit | 800f9c203728ee84d50181af6fa34ac9e5c04e73 (patch) | |
tree | 69192ea9020cffb5a6a51557f17105ec10d76bb5 /lib/options.nix | |
parent | 4680af6a9334297885a96ba464d58316587a87fd (diff) |
Show correct position info for errors in submodules
E.g. The unique option `fileSystems./.device' is defined multiple times, in `/etc/nixos/configuration.nix' and `/etc/nixos/foo.nix'. This requires passing file/value tuples to the merge functions.
Diffstat (limited to 'lib/options.nix')
-rw-r--r-- | lib/options.nix | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/options.nix b/lib/options.nix index 2b211478765de..5a05775e8c252 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -30,36 +30,39 @@ rec { type = lib.types.bool; }; - mergeDefaultOption = args: list: + mergeDefaultOption = loc: defs: + let list = getValues defs; in if length list == 1 then head list - else if all builtins.isFunction list then x: mergeDefaultOption args (map (f: f x) list) + else if all builtins.isFunction list then x: mergeDefaultOption loc (map (f: f x) list) else if all isList list then concatLists list else if all isAttrs list then fold lib.mergeAttrs {} list else if all builtins.isBool list then fold lib.or false list else if all builtins.isString list then lib.concatStrings list else if all builtins.isInt list && all (x: x == head list) list then head list - else throw "Cannot merge definitions of `${showOption args.prefix}' given in ${showFiles args.files}."; + else throw "Cannot merge definitions of `${showOption loc}' given in ${showFiles (getFiles defs)}."; /* Obsolete, will remove soon. Specify an option type or apply function instead. */ - mergeTypedOption = typeName: predicate: merge: args: list: - if all predicate list then merge list - else throw "Expect a ${typeName}."; + mergeTypedOption = typeName: predicate: merge: loc: list: + let list' = map (x: x.value) list; in + if all predicate list then merge list' + else throw "Expected a ${typeName}."; mergeEnableOption = mergeTypedOption "boolean" (x: true == x || false == x) (fold lib.or false); mergeListOption = mergeTypedOption "list" isList concatLists; - mergeStringOption = mergeTypedOption "string" - (x: if builtins ? isString then builtins.isString x else x + "") - lib.concatStrings; + mergeStringOption = mergeTypedOption "string" builtins.isString lib.concatStrings; - mergeOneOption = args: list: - if list == [] then abort "This case should never happen." - else if length list != 1 then - throw "The unique option `${showOption args.prefix}' is defined multiple times, in ${showFiles args.files}." - else head list; + mergeOneOption = loc: defs: + if defs == [] then abort "This case should never happen." + else if length defs != 1 then + throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}." + else (head defs).value; + + getValues = map (x: x.value); + getFiles = map (x: x.file); # Generate documentation template from the list of option declaration like |