From f463d2490322a7a7e41634bbf23fc9cbdbdb9fae Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Jul 2015 13:36:57 +0200 Subject: Add read-only options These are options that can have only one definition, regardless of priority. --- lib/modules.nix | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/modules.nix') diff --git a/lib/modules.nix b/lib/modules.nix index d7037abfbef..50827e18f10 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -261,11 +261,16 @@ rec { evalOptionValue = loc: opt: defs: let # Add in the default value for this option, if any. - defs' = (optional (opt ? default) - { file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs; + defs' = + (optional (opt ? default) + { file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs; # Handle properties, check types, and merge everything together. - res = mergeDefinitions loc opt.type defs'; + res = + if opt.readOnly or false && length defs' > 1 then + throw "The option `${showOption loc}' is read-only, but it's set multiple times." + else + mergeDefinitions loc opt.type defs'; # Check whether the option is defined, and apply the ‘apply’ # function to the merged value. This allows options to yield a -- cgit 1.4.1