Is it possible to override only part of a default value?

Hello There,

I’ve seen this topic here: How can I augment a default value instead of overriding it? - #4 by mvnetbiz, but I feel like my use case is slightly different.

I’m trying to setup a Nextcloud instance and one of the options is NixOS Search. I would like to keep the default payload but just would like to swap the value of ```
“opcache.interned_strings_buffer”. Is there a way of doing that ? I tried doing:

    phpOptions = lib.mkOptionDefault {
      "opcache.interned_strings_buffer" = 16;
    };

But it does not seem to work and in my understanding doing:

    phpOptions =  {
      "opcache.interned_strings_buffer" = 16;
    };

would replace the whole payload by this one. Is there a way to keep the original one but just tune it for this specific line ?

Have you tried this? I would actually expect it to replace only this one option and keep the rest unchanged. To clear all of the phpOptions and use only the ones you specify, you’d need something like lib.mkForce.

See https://nixos.org/manual/nixos/stable/#sec-option-definitions-setting-priorities. lib.mkOptionDefault appears to be undocumented - it’s the same as setting default = in a mkOption call, i.e. it’s priority 1500. And if same priorities are given (100, if you don’t specify) then definitions get merged according to the merge function provided to mkOptionType.

The option description says the same thing, even:

Please note that this option is additive on purpose while the attribute values inside the default are option defaults: that means that

{
  services.nextcloud.phpOptions."opcache.interned_strings_buffer" = "23";
}

will override the php.ini option opcache.interned_strings_buffer without discarding the rest of the defaults.

So, you need a priority higher than 100 to wipe out existing config, and the easiest way to do that is via lib.mkForce (50). So what you’re reporting doesn’t track for me.

@rhendric @waffle8946 I’m really sorry. I should have slept on it, I obviously was tired and did not see what was in front of my eyes. Too much NixOs config for one day.

Thanks for your answers and for pointing it out, and again, sorry for the trouble, it was all very much documented.

2 Likes