Show precise error messages in option merge failures
For instance, if time.timeZone is defined multiple times, you now get the error message: error: user-thrown exception: The unique option `time.timeZone' is defined multiple times, in `/etc/nixos/configurations/misc/eelco/x11vnc.nix' and `/etc/nixos/configuration.nix'. while previously you got: error: user-thrown exception: Multiple definitions of string. Only one is allowed for this option. and only an inspection of the stack trace gave a clue as to what option caused the problem.
This commit is contained in:
@@ -25,11 +25,14 @@ in
|
||||
'';
|
||||
type = types.attrsOf (mkOptionType {
|
||||
name = "a string or a list of strings";
|
||||
merge = xs:
|
||||
merge = args: xs:
|
||||
let xs' = filterOverrides xs; in
|
||||
if isList (head xs') then concatLists xs'
|
||||
else if builtins.lessThan 1 (length xs') then abort "variable in ‘environment.variables’ has multiple values"
|
||||
else if !builtins.isString (head xs') then abort "variable in ‘environment.variables’ does not have a string value"
|
||||
else if builtins.lessThan 1 (length xs') then
|
||||
# Don't show location info here, since it's too general.
|
||||
throw "The option `${showOption args.prefix}' is defined multiple times."
|
||||
else if !builtins.isString (head xs') then
|
||||
throw "The option `${showOption args.prefix}' does not have a string value."
|
||||
else head xs';
|
||||
});
|
||||
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
||||
|
||||
Reference in New Issue
Block a user