diff options
author | toastal <toastal@posteo.net> | 2024-03-18 15:50:57 +0700 |
---|---|---|
committer | toastal <toastal@posteo.net> | 2024-04-11 23:26:11 +0700 |
commit | 0ba23300dec970d3226841a0002e1dd0a4320430 (patch) | |
tree | 1bf823f955c753ac5ea6508a9128db19c4b7305b /nixos/modules/services/web-apps | |
parent | 64b110589cf76e4eaa6ff1c79b162418cccae3a4 (diff) |
nixos/movim: precompress static files
Diffstat (limited to 'nixos/modules/services/web-apps')
-rw-r--r-- | nixos/modules/services/web-apps/movim.nix | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/nixos/modules/services/web-apps/movim.nix b/nixos/modules/services/web-apps/movim.nix index d7f6ad5bb5ef..bb88a185b461 100644 --- a/nixos/modules/services/web-apps/movim.nix +++ b/nixos/modules/services/web-apps/movim.nix @@ -91,6 +91,37 @@ let '') [ ] cfg.podConfig)); + + precompressStaticFilesJobs = + let + inherit (cfg.precompressStaticFiles) brotli gzip; + + findTextFileNames = lib.concatStringsSep " -o " + (builtins.map (n: ''-iname "*.${n}"'') + [ "css" "ini" "js" "json" "manifest" "mjs" "svg" "webmanifest" ]); + in + lib.concatStringsSep "\n" [ + (lib.optionalString brotli.enable '' + echo -n "Precompressing static files with Brotli …" + find ${appDir}/public -type f ${findTextFileNames} \ + | ${lib.getExe pkgs.parallel} ${lib.escapeShellArgs [ + "--will-cite" + "-j $NIX_BUILD_CORES" + "${lib.getExe brotli.package} --keep --quality=${builtins.toString brotli.compressionLevel} --output={}.br {}" + ]} + echo " done." + '') + (lib.optionalString gzip.enable '' + echo -n "Precompressing static files with Gzip …" + find ${appDir}/public -type f ${findTextFileNames} \ + | ${lib.getExe pkgs.parallel} ${lib.escapeShellArgs [ + "--will-cite" + "-j $NIX_BUILD_CORES" + "${lib.getExe gzip.package} -c -${builtins.toString gzip.compressionLevel} {} > {}.gz" + ]} + echo " done." + '') + ]; in { postInstall = lib.concatStringsSep "\n\n" [ @@ -98,6 +129,7 @@ let stateDirectories exposeComposer podConfigInputDisableReplace + precompressStaticFilesJobs ]; }); @@ -224,6 +256,36 @@ in description = "Do minification on public static files"; }; + precompressStaticFiles = mkOption { + type = with types; submodule { + options = { + brotli = { + enable = mkEnableOption "Brotli precompression"; + package = mkPackageOption pkgs "brotli" { }; + compressionLevel = mkOption { + type = types.ints.between 0 11; + default = 11; + description = "Brotli compression level"; + }; + }; + gzip = { + enable = mkEnableOption "Gzip precompression"; + package = mkPackageOption pkgs "gzip" { }; + compressionLevel = mkOption { + type = types.ints.between 1 9; + default = 9; + description = "Gzip compression level"; + }; + }; + }; + }; + default = { + brotli.enable = true; + gzip.enable = false; + }; + description = "Aggressively precompress static files"; + }; + podConfig = mkOption { type = types.submodule { options = { |