mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 14:26:33 +01:00
e878fc4aac
I recently wrote some Nix code where I wrongly set a value to an option which wasn't an actual option, but an attr-set of options. The mistake I made can be demonstrated with an expression like this: { foo = { lib, pkgs, config, ... }: with lib; { options.foo.bar.baz = mkOption { type = types.str; }; config.foo.bar = 23; }; } While it wasn't too hard to find the cause of the mistake for me, it was necessary to have some practice in reading stack traces from the module system since the eval-error I got was not very helpful: error: --- TypeError --------------------------------------------------------- nix-build at: (323:25) in file: /nix/store/3nm31brdz95pj8gch5gms6xwqh0xx55c-source/lib/modules.nix 322| foldl' (acc: module: 323| acc // (mapAttrs (n: v: | ^ 324| (acc.${n} or []) ++ f module v value is an integer while a set was expected (use '--show-trace' to show detailed location information) I figured that such an error can be fairly confusing for someone who's new to NixOS, so I decided to catch this case in th `byName` function in `lib/modules.nix` by checking if the value to map through is an actual attr-set. If not, a different error will be thrown. |
||
---|---|---|
.. | ||
systems | ||
tests | ||
asserts.nix | ||
attrsets.nix | ||
cli.nix | ||
customisation.nix | ||
debug.nix | ||
default.nix | ||
deprecated.nix | ||
fetchers.nix | ||
filesystem.nix | ||
fixed-points.nix | ||
generators.nix | ||
kernel.nix | ||
licenses.nix | ||
lists.nix | ||
meta.nix | ||
minver.nix | ||
modules.nix | ||
options.nix | ||
sources.nix | ||
strings-with-deps.nix | ||
strings.nix | ||
trivial.nix | ||
types.nix | ||
versions.nix | ||
zip-int-bits.nix |