3
0
Fork 0
forked from mirrors/nixpkgs
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 lib: move assertMsg and assertOneOf to their own library file 2018-09-06 18:14:27 +02:00
attrsets.nix lib/attrsets: add getMan function 2020-06-18 10:16:57 +02:00
cli.nix lib/cli: mkKey -> mkOptionName, use generators.mkValueStringDefault 2020-01-23 14:47:38 +01:00
customisation.nix lib.callPackages(With): guard against a repeated mistake 2020-03-12 09:40:15 +01:00
debug.nix lib/debug: Update documentation comments for docs generation 2018-10-29 10:45:25 +01:00
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 lib.converge: optimise 2019-04-17 15:55:57 +01:00
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 lib: implement setPrio 2018-11-22 08:59:48 +00:00
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 lib/versions: expose splitVersion 2019-09-26 17:42:42 +02:00
zip-int-bits.nix lib/trivial: move zipIntBits to its own file 2018-07-26 20:36:45 +02:00