From 5b820b674a9227414253b7f911f921c22592065d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=82=E0=B8=97=E0=B8=AA=E0=B8=BA=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=A5?= Date: Mon, 10 Mar 2025 22:32:54 +0700 Subject: [PATCH] nixos/movim: fix minification options & document them Removes the packages since this can be overridden with services.movim.package. --- nixos/modules/services/web-apps/movim.nix | 72 ++++++++++++++++------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/nixos/modules/services/web-apps/movim.nix b/nixos/modules/services/web-apps/movim.nix index 07ff67233317..ded4e30b5bfb 100644 --- a/nixos/modules/services/web-apps/movim.nix +++ b/nixos/modules/services/web-apps/movim.nix @@ -61,14 +61,6 @@ let // lib.optionalAttrs (cfg.database.type == "mysql") { withMySQL = true; } - // lib.optionalAttrs (lib.isAttrs cfg.minifyStaticFiles) ( - with cfg.minifyStaticFiles; - { - esbuild = esbuild.package; - lightningcss = lightningcss.package; - scour = scour.package; - } - ) ); in p.overrideAttrs ( @@ -258,18 +250,21 @@ in }; minifyStaticFiles = mkOption { - type = - with types; - either bool (submodule { + type = types.either types.bool ( + types.submodule { options = { script = mkOption { type = types.submodule { options = { - enable = mkEnableOption "Script minification"; - package = mkPackageOption pkgs "esbuild" { }; + enable = mkEnableOption "Script minification via esbuild"; target = mkOption { - type = with types; nullOr nonEmptyStr; + type = types.nullOr types.nonEmptyStr; default = null; + description = '' + esbuild target environment string. If not set, a sane + default will be provided. See: + . + ''; }; }; }; @@ -277,11 +272,15 @@ in style = mkOption { type = types.submodule { options = { - enable = mkEnableOption "Script minification"; - package = mkPackageOption pkgs "lightningcss" { }; + enable = mkEnableOption "Script minification via Lightning CSS"; target = mkOption { - type = with types; nullOr nonEmptyStr; + type = types.nullOr types.nonEmptyStr; default = null; + description = '' + Browserslists string target for browser compatibility. + If not set, a sane default will be provided. See: + . + ''; }; }; }; @@ -289,15 +288,34 @@ in svg = mkOption { type = types.submodule { options = { - enable = mkEnableOption "SVG minification"; - package = mkPackageOption pkgs "scour" { }; + enable = mkEnableOption "SVG minification via Scour"; }; }; }; }; - }); + } + ); default = true; - description = "Do minification on public static files"; + description = '' + Do minification on public static files which reduces the size of + assets — saving data for the server & users as well as offering a + performance improvement. This adds typing for the `minifyStaticFiles` + attribute for the Movim package which *will* override any existing + override value. The default `true` will enable minification for all + supported asset types with sane defaults. + ''; + example = + lib.literalExpression # nix + '' + { + script.enable = false; + style = { + enable = true; + target = "> 0.5%, last 2 versions, Firefox ESR, not dead"; + }; + svg.enable = true; + } + ''; }; precompressStaticFiles = mkOption { @@ -818,4 +836,16 @@ in }; }; }; + + imports = [ + (lib.mkRemovedOptionModule [ "minifyStaticFiles" "script" "package" ] '' + Override services.movim.package instead. + '') + (lib.mkRemovedOptionModule [ "minifyStaticFiles" "style" "package" ] '' + Override services.movim.package instead. + '') + (lib.mkRemovedOptionModule [ "minifyStaticFiles" "svg" "package" ] '' + Override services.movim.package instead. + '') + ]; }