foobar
April 30, 2023, 7:55am
1
Hi folks,
Could you please explain me in the following code:
{
options.foo = {
first = mkEnableOption "";
second = mkOption {
type = types.bool;
};
third = mkOption {
type = types.bool;
default = true;
};
};
}
Is there a difference between first and second option?
And correct me if I’m wrong. If I want to specify the third option, that can’t be done using mkEnableOption
.
Thank you for Nix / NixOS. It’s amazing project. And thank you for this community ;-).
The description gets prefixed with “Whether to enable”. You can see the full definition here: nixpkgs/options.nix at 468356287fe4ce68f58fa5cf16e8ed6fc40a1a7f · NixOS/nixpkgs · GitHub
You can get almost the same effect as the third option by also setting:
config.third = lib.mkDefault true;
(There is a slight difference between mkDefault and the default of an option. The default of an option has an even lower priority than mkDefault)
2 Likes
foobar
April 30, 2023, 8:20am
3
Thank you very much.
bobvanderlinden:
lib.mkDefault true;`
Is that type checked? For example if I use true
for boolean or if I use “abc” for string?
Yes, setting “abc” will fail.
The type determines what may be filled in. Functions like mkDefault merely determine what happens when the option is set in multiple places (there is a merging mechanism for those cases). The eventual value must be of type bool.
foobar
April 30, 2023, 9:39am
5
Ouh, I get it. Probably something I don’t need for options / config.
I realized the auto generated config has:
networking.useDHCP = lib.mkDefault true;
So If I want I can replace it by
networking.useDHCP = true;
and assuming I’m not setting networking.useDHCP
in multiple files, the effect will be the same.
Thank you.
1 Like