From b3cc29c288b6ac5e2fa71477cabb2d088f568001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 9 Feb 2023 07:25:50 +0000 Subject: [PATCH 1/2] types: explicitly state unique options are expected to be unique --- lib/options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/options.nix b/lib/options.nix index d14d209a8347..22eb6c2eeb1d 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -184,7 +184,7 @@ rec { if length defs == 1 then (head defs).value else assert length defs > 1; - throw "The option `${showOption loc}' is defined multiple times.\n${message}\nDefinition values:${showDefs defs}"; + throw "The option `${showOption loc}' is defined multiple times while it's expected to be unique.\n${message}\nDefinition values:${showDefs defs}"; /* "Merge" option definitions by checking that they all have the same value. */ mergeEqualOption = loc: defs: From fe734efc9c2c0a42b9c34dfd6280d82558744a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 9 Feb 2023 07:38:40 +0000 Subject: [PATCH 2/2] types: suggest how to resolve the conflict --- lib/options.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/options.nix b/lib/options.nix index 22eb6c2eeb1d..5e8f4ca4bb95 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -36,6 +36,9 @@ let inherit (lib.types) mkOptionType ; + prioritySuggestion = '' + Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions. + ''; in rec { @@ -184,7 +187,7 @@ rec { if length defs == 1 then (head defs).value else assert length defs > 1; - throw "The option `${showOption loc}' is defined multiple times while it's expected to be unique.\n${message}\nDefinition values:${showDefs defs}"; + throw "The option `${showOption loc}' is defined multiple times while it's expected to be unique.\n${message}\nDefinition values:${showDefs defs}\n${prioritySuggestion}"; /* "Merge" option definitions by checking that they all have the same value. */ mergeEqualOption = loc: defs: @@ -195,7 +198,7 @@ rec { else if length defs == 1 then (head defs).value else (foldl' (first: def: if def.value != first.value then - throw "The option `${showOption loc}' has conflicting definition values:${showDefs [ first def ]}" + throw "The option `${showOption loc}' has conflicting definition values:${showDefs [ first def ]}\n${prioritySuggestion}" else first) (head defs) (tail defs)).value;