diff options
author | Maximilian Bosch <maximilian@mbosch.me> | 2023-08-05 11:23:58 +0200 |
---|---|---|
committer | Maximilian Bosch <maximilian@mbosch.me> | 2023-08-05 11:58:11 +0200 |
commit | 2ddb1453e6fadb7ac10d3c9996a9f3f7356deb76 (patch) | |
tree | f53c20b276011a481b9c34a7332eb09e1deb37e5 /nixos/modules/services/web-apps/nextcloud.nix | |
parent | ed02e79bbe031a7ce9cf863660f10d3ef70b8636 (diff) |
nixos/nextcloud: make php settings additive
Right now, the settings aren't additive which means that when I do services.nextcloud.phpOptions."opcache.interned_strings_buffer = "23"; all other options are discarded because of how the module system works. This isn't very nice in this case, though because wanting to override a single option doesn't mean I want to discard the rest of the - reasonable - defaults. Hence, the settings are showed as default in the option's manual section, but are added with normal priority. That means, to override _all_ options at once, an expression like services.nextcloud.phpOptions = mkForce { /* ... */ }; is needed. This is also way more intuitive IMHO because the `mkForce` explicitly tells that everything will be modified. Also, APCu enable and the memory & file-size limits are also written into `services.nextcloud.phpOptions` rather than adding them silently before passing all options to the PHP package. This has the benefit that users will realize on evaluation time that they configured options that would otherwise be set by the module on its own.
Diffstat (limited to 'nixos/modules/services/web-apps/nextcloud.nix')
-rw-r--r-- | nixos/modules/services/web-apps/nextcloud.nix | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/nixos/modules/services/web-apps/nextcloud.nix b/nixos/modules/services/web-apps/nextcloud.nix index 06af9d933e084..078164866dd62 100644 --- a/nixos/modules/services/web-apps/nextcloud.nix +++ b/nixos/modules/services/web-apps/nextcloud.nix @@ -8,6 +8,21 @@ let jsonFormat = pkgs.formats.json {}; + defaultPHPSettings = { + short_open_tag = "Off"; + expose_php = "Off"; + error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT"; + display_errors = "stderr"; + "opcache.enable_cli" = "1"; + "opcache.interned_strings_buffer" = "8"; + "opcache.max_accelerated_files" = "10000"; + "opcache.memory_consumption" = "128"; + "opcache.revalidate_freq" = "1"; + "opcache.fast_shutdown" = "1"; + "openssl.cafile" = "/etc/ssl/certs/ca-certificates.crt"; + catch_workers_output = "yes"; + }; + inherit (cfg) datadir; phpPackage = cfg.phpPackage.buildEnv { @@ -26,22 +41,13 @@ let ++ optional cfg.caching.memcached memcached ) ++ cfg.phpExtraExtensions all; # Enabled by user - extraConfig = toKeyValue phpOptions; + extraConfig = toKeyValue cfg.phpOptions; }; toKeyValue = generators.toKeyValue { mkKeyValue = generators.mkKeyValueDefault {} " = "; }; - phpOptions = { - upload_max_filesize = cfg.maxUploadSize; - post_max_size = cfg.maxUploadSize; - memory_limit = cfg.maxUploadSize; - } // cfg.phpOptions - // optionalAttrs cfg.caching.apcu { - "apc.enable_cli" = "1"; - }; - occ = pkgs.writeScriptBin "nextcloud-occ" '' #! ${pkgs.runtimeShell} cd ${cfg.package} @@ -263,22 +269,33 @@ in { phpOptions = mkOption { type = types.attrsOf types.str; - default = { - short_open_tag = "Off"; - expose_php = "Off"; - error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT"; - display_errors = "stderr"; - "opcache.enable_cli" = "1"; - "opcache.interned_strings_buffer" = "8"; - "opcache.max_accelerated_files" = "10000"; - "opcache.memory_consumption" = "128"; - "opcache.revalidate_freq" = "1"; - "opcache.fast_shutdown" = "1"; - "openssl.cafile" = "/etc/ssl/certs/ca-certificates.crt"; - catch_workers_output = "yes"; - }; + defaultText = literalExpression (generators.toPretty { } defaultPHPSettings); description = lib.mdDoc '' Options for PHP's php.ini file for nextcloud. + + Please note that this option is _additive_ on purpose while the + attribute values inside the default are option defaults: that means that + + ```nix + { + 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. + + Overriding all of `phpOptions` (including `upload_max_filesize`, `post_max_size` + and `memory_limit` which all point to [](#opt-services.nextcloud.maxUploadSize) + by default) can be done like this: + + ```nix + { + services.nextcloud.phpOptions = lib.mkForce { + /* ... */ + }; + } + ``` ''; }; @@ -750,6 +767,18 @@ in { services.nextcloud.phpPackage = if versionOlder cfg.package.version "26" then pkgs.php81 else pkgs.php82; + + services.nextcloud.phpOptions = mkMerge [ + (mapAttrs (const mkOptionDefault) defaultPHPSettings) + { + upload_max_filesize = cfg.maxUploadSize; + post_max_size = cfg.maxUploadSize; + memory_limit = cfg.maxUploadSize; + } + (mkIf cfg.caching.apcu { + "apc.enable_cli" = "1"; + }) + ]; } { assertions = [ |