nixpkgs/lib
Maximilian Bosch fa30c9abed
lib/modules: improve error-message for undeclared options if prefix contains no options
An easy-to-make mistake when declaring e.g. a submodule is the accidental
confusion of `options` and `config`:

    types.submodule {
      config = {
        foo = mkOption { /* ... */ };
      };
    }

However the error-message

  The option `[definition 1-entry 1].foo' defined in `<expr.nix>' does not exist.

is fairly unhelpful because it seems as the options are declared at the
first sight. In fact, it took a colleague and me a while to track down such
a mistake a few days ago and we both agreed that this should be somehow caught
to save the time we spent debugging the module in question.

At first I decided to catch this error in the `submodules`-type directly
by checking whether `options` is undeclared, however this becomes fairly
complicated as soon as a submodule-declaration e.g. depends on existing
`config`-values which would've lead to some ugly `builtins.tryExec`-heuristic.

This patch now simply checks if the option's prefix has any options
defined if a point in evaluation is reached where it's clear that the
option in question doesn't exist. This means that this patch doesn't
change the logic of the module system, it only provides a more detailed
error in certain cases:

  The option `[definition 1-entry 1].foo' defined in `<expr.nix>' does not exist.

  However it seems as there are no options defined in [definition 1-entry 1]. Are you sure you've
  declared your options properly? This happens if you e.g. declared your options in `types.submodule'
  under `config' rather than `options'.
2020-08-18 15:25:26 +02:00
..
systems Define a i686-genode system double 2020-08-04 18:08:56 +02:00
tests Merge pull request #82743 from Infinisil/partially-typed-v2 2020-08-15 12:13:58 +02:00
asserts.nix
attrsets.nix lib/attrsets: add getMan function 2020-06-18 10:16:57 +02:00
cli.nix
customisation.nix
debug.nix
default.nix lib: toHex -> toHexString & toBase -> toBaseDigits 2020-07-20 13:14:19 +02:00
deprecated.nix lib.fake{Sri => Hash}: fix and rename 2020-05-11 23:11:12 +01:00
fetchers.nix
filesystem.nix
fixed-points.nix
generators.nix lib/generators: Extend mkValueStringDefault with float support 2020-07-29 18:06:34 +02:00
kernel.nix Merge pull request #84032 from teto/fix_kernel_merge 2020-05-22 13:32:22 +02:00
licenses.nix licenses: add BlueOak-1.0.0 2020-08-17 12:29:16 -07:00
lists.nix fix example for foldl 2020-05-08 08:31:27 -04:00
meta.nix
minver.nix Bump minver.nix to 2.2 2020-06-04 13:43:10 +02:00
modules.nix lib/modules: improve error-message for undeclared options if prefix contains no options 2020-08-18 15:25:26 +02:00
options.nix lib/options: fix showOption example 2020-04-14 20:38:31 +02:00
sources.nix commitIdFromGitRepo: fix stackoverflow if many branches are used. 2020-07-17 10:44:08 +01:00
strings-with-deps.nix
strings.nix lib/strings: Add floatToString 2020-07-25 21:43:09 +02:00
trivial.nix lib: toHex -> toHexString & toBase -> toBaseDigits 2020-07-20 13:14:19 +02:00
types.nix lib/types: Make submodules use the freeform type description 2020-08-03 22:37:01 +02:00
versions.nix
zip-int-bits.nix