summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2021-07-23 10:56:24 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2021-08-25 23:18:27 +0200
commitb6d3c9f821b704fbfb68d20a76520fa9e160df36 (patch)
tree08aef81024286917fbc0f617b1796e800e4cf026 /lib/modules.nix
parentfbc9084c39297f6a8ca618b0f6a3ccdd4489ab6a (diff)
downloadnixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar.gz
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar.bz2
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar.lz
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar.xz
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.tar.zst
nixpkgs-b6d3c9f821b704fbfb68d20a76520fa9e160df36.zip
lib/modules: fix error-message when declaring an option inside `config'
The message I originally implemented here was to catch a mixup of
`config' and `options' in a `types.submodule'[1]. However it looks
rather weird for a wrongly declared top-level option.

So I decided to throw

    error: The option `foo' does not exist. Definition values:
           - In `<unknown-file>':
               {
                 bar = {
                   _type = "option";
                   type = {
                     _type = "option-type";
               ...

           It seems as you're trying to declare an option by placing it into `config' rather than `options'!

for an expression like

    with import ./lib;

    evalModules {
      modules = [
        {
          foo.bar = mkOption {
            type = types.str;
          };
        }
      ];
    }

[1]  fa30c9abed61f30218a211842204705986d486f9
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index b124ea000a2..51e12f0659c 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -162,13 +162,24 @@ rec {
             baseMsg = "The option `${showOption (prefix ++ firstDef.prefix)}' does not exist. Definition values:${showDefs [ firstDef ]}";
           in
             if attrNames options == [ "_module" ]
-              then throw ''
-                ${baseMsg}
-
-                However there are no options defined in `${showOption prefix}'. Are you sure you've
-                declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
-                under `config' rather than `options'.
-              ''
+              then
+                let
+                  optionName = showOption prefix;
+                in
+                  if optionName == ""
+                    then throw ''
+                      ${baseMsg}
+
+                      It seems as you're trying to declare an option by placing it into `config' rather than `options'!
+                    ''
+                  else
+                    throw ''
+                      ${baseMsg}
+
+                      However there are no options defined in `${showOption prefix}'. Are you sure you've
+                      declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
+                      under `config' rather than `options'.
+                    ''
             else throw baseMsg
         else null;