From d0328b363cad01e6772c03b7fef000d023dbfc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 16:19:46 +0200 Subject: [PATCH] gamja: compress --- flake.nix | 2 ++ hosts/vno1-oh2/configuration.nix | 2 +- pkgs/gamja.nix | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 7a6ee3d..bdeb82a 100644 --- a/flake.nix +++ b/flake.nix @@ -322,6 +322,8 @@ }; }; + packages.gamja = pkgs.gamja; + devShells.default = pkgs.mkShellNoCC { packages = [ pkgs.rage diff --git a/hosts/vno1-oh2/configuration.nix b/hosts/vno1-oh2/configuration.nix index 93c474e..1c696d9 100644 --- a/hosts/vno1-oh2/configuration.nix +++ b/hosts/vno1-oh2/configuration.nix @@ -303,7 +303,7 @@ abort @denied tls {$CREDENTIALS_DIRECTORY}/irc.jakstys.lt-cert.pem {$CREDENTIALS_DIRECTORY}/irc.jakstys.lt-key.pem - root * ${pkgs.gamja} + root * ${pkgs.gamja.passthru.data-compressed} file_server browse { precompressed br gzip } diff --git a/pkgs/gamja.nix b/pkgs/gamja.nix index d3c1e43..c259075 100644 --- a/pkgs/gamja.nix +++ b/pkgs/gamja.nix @@ -1,9 +1,14 @@ { lib, + gamja, fetchFromSourcehut, buildNpmPackage, + runCommand, python3, writeText, + brotli, + zopfli, + xorg, # optional configuration attrSet, see https://git.sr.ht/~emersion/gamja#configuration-file for possible values gamjaConfig ? null, }: @@ -32,6 +37,25 @@ buildNpmPackage rec { runHook postInstall ''; + passthru = { + data-compressed = + runCommand "soju-data-compressed" { + nativeBuildInputs = [brotli zopfli xorg.lndir]; + } '' + mkdir $out + lndir ${gamja}/ $out/ + + find $out \ + -name '*.css' -or \ + -name '*.js' -or \ + -name '*.map' -or \ + -name '*.webmanifest' -or \ + -name '*.html' | \ + tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \ + xargs -n1 -P''$(nproc) ${brotli}/bin/brotli + ''; + }; + meta = with lib; { description = "A simple IRC web client"; homepage = "https://git.sr.ht/~emersion/gamja";