-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/modules: Report a good error when option tree has bare type #242339
Conversation
Note that this removes the possibility of declaring an option named `_type`.
d93ccfc
to
0d472a6
Compare
I am not sure to give that feedback here or not, but i give it a try. First of all thanks for that check, it did find a very nasty error in one of my custom modules (didnt use the module atm, so but still it was an error). The module was the following code basically {
lib,
...
}: let
cfg = config.stuff;
in {
options = {
stuff = { enable = lib.mkEnableOption "does somehting useful"; }
config = mkIf cfg.enable {
....
};
}; So one may see that the config is defined inside the options, which is the error. And super nice that the module system now complains when that occurs. 👍 So the error message occuring is correct, but sadly does not really help the user to find the problem, as with the module the error is error: Expected an option declaration at option path `config`, config but got an attribute set with type if To actually help the user it would be great if we could either add to the output the configuration path, so in that case I found the problematic module at the end by commenting out code until eval unbroke again. The stacktrace that was produced was the following:
The original problematic module code is https://github.com/Shawn8901/nix-configuration/blob/2d13dcbb4a5e4b88038d36e9bfd47dda293aa239/modules/nixos/_private/backup-rclone.nix#L21 and the machines |
Improves on 0d472a6 - NixOS#242339 We actually do have the file name. Thanks Shawn8901 for the [feedback]! feedback: NixOS#242339 (comment)
Improves on 239f44b - NixOS/nixpkgs#242339 We actually do have the file name. Thanks Shawn8901 for the [feedback]! feedback: NixOS/nixpkgs#242339 (comment)
Improves on 7892813 - NixOS/nixpkgs#242339 We actually do have the file name. Thanks Shawn8901 for the [feedback]! feedback: NixOS/nixpkgs#242339 (comment)
Improves on e78b909 - NixOS/nixpkgs#242339 We actually do have the file name. Thanks Shawn8901 for the [feedback]! feedback: NixOS/nixpkgs#242339 (comment)
Description of changes
Catch a common mistake.
Example message
This removes the possibility of creating an option named
_type
.Excuse my clever use of
&&
and||
. It's performance critical code, so I prefer to avoid unnecessary function calls, and to a degree unnecessary AST nodes. Speaking of, this code should be an ever so slight improvement, for avoiding theisType
function call with its associatedEnv
allocation (and other complexity).Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)