Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add option parameter for default value priority
When you define an option's default value, the expectation is that whenever the option is set somewhere, the default value will be overridden by that setting rather than merged. It's sometimes the case however that your option's default value should be merged with what is being set rather than overwritten by it; only allowing explicit overrides via `mkForce`. Creating such an option was not possible previously as all options' default values were forcefully clamped via mkOptionDefault. There were some workarounds such as creating additional options ("things" + "extraThings") which you'd then have to explain to users and generally aren't ergonomical to use. Another workaround was to explicitly set options value to the default value in the implementation but those two lines of code might be many lines apart from another and it's generally an odd pattern. Example: { options.foo = lib.mkOption { default = [ "foo" ]; }; # Many more lines of code config.foo = options.foo.default; } It is now possible to control this behaviour at option declaration which is much clearer in the code and is introspect-able. { options.foo = lib.mkOption { default = [ "foo" ]; defaultPriority = lib.modules.priorities.baseline; }; # Many more lines of code } The implementation is trivial. If this becomes used more widely, it should be rendered in the generated options manual and nixos-search.
- Loading branch information