If I’m understanding it correctly, there are two ways how to provide a default value to an option:
- By using
lib.mkDefault <value>
- By setting the
default attribute in lib.mkOption.
What is the difference between those two? When should I use which version?
https://nixos.org/manual/nixos/unstable/#sec-option-definitions-setting-priorities
option defaults have priority 1500
mkDefault is equal to mkOverride 1000 .
So, lib.mkDefault has higher prio than default. Of course, setting an option with no modifier will have even higher prio (100).
Also, only option defaults (default) will be present in the generated documentation, unless you set defaultText manually.
2 Likes