summary refs log tree commit diff
path: root/lib/options.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-15 18:04:27 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-15 18:07:48 +0200
commite212e07cf6aac9d9e1c46db34b17fd16be2399c3 (patch)
treec8e6598f823255362e6f3ff703e359a0bfa3ffc6 /lib/options.nix
parenta4925bcfa8ba5517dda7fa5369b2493f363936af (diff)
downloadnixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar.gz
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar.bz2
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar.lz
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar.xz
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.tar.zst
nixpkgs-e212e07cf6aac9d9e1c46db34b17fd16be2399c3.zip
Make types.bool complain on conflicting definitions
Previously, conflicting definitions would merge to "true". Now they
give an error, e.g.

  error: The option `hardware.enableAllFirmware' has conflicting definitions, in `/etc/nixos/configurations/misc/eelco/stuff.nix' and `/etc/nixos/configurations/misc/eelco/mandark.nix'.
Diffstat (limited to 'lib/options.nix')
-rw-r--r--lib/options.nix9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/options.nix b/lib/options.nix
index a30397c7216..bfc5b5fa2ae 100644
--- a/lib/options.nix
+++ b/lib/options.nix
@@ -65,6 +65,15 @@ rec {
       throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
     else (head defs).value;
 
+  /* "Merge" option definitions by checking that they all have the same value. */
+  mergeEqualOption = loc: defs:
+    if defs == [] then abort "This case should never happen."
+    else fold (def: val:
+      if def.value != val then
+        throw "The option `${showOption loc}' has conflicting definitions, in ${showFiles (getFiles defs)}."
+      else
+        val) (head defs).value defs;
+
   getValues = map (x: x.value);
   getFiles = map (x: x.file);