From 30ebec15183581a33bd0af48cbbcc082a8b35966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alu=C3=ADsio=20Augusto=20Silva=20Gon=C3=A7alves?= Date: Tue, 20 Apr 2021 20:29:19 -0300 Subject: [PATCH] aasg-brotlify: New hook to auto-compress static websites aasgBrotlifyHook can be passed in a derivation's `nativeBuildInputs` to compress all HTML, CSS, and JS files in the output (as well as the corrresponding source maps) with Brotli. It is expected to be used by packages that are or contain websites. --- flake.nix | 2 +- pkgs/build-support/aasg-brotlify/default.nix | 2 ++ pkgs/build-support/aasg-brotlify/setup-hook.sh | 6 ++++++ pkgs/manifest.nix | 1 + pkgs/overlay.nix | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 pkgs/build-support/aasg-brotlify/default.nix create mode 100644 pkgs/build-support/aasg-brotlify/setup-hook.sh diff --git a/flake.nix b/flake.nix index 44b6646..fa197f8 100644 --- a/flake.nix +++ b/flake.nix @@ -24,7 +24,7 @@ # Flatten package sets. flattenTree # Remove packages not compatible with this system. - (filterAttrs (attr: drv: builtins.elem system drv.meta.platforms)) + (filterAttrs (attr: drv: drv ? meta.platforms -> builtins.elem system drv.meta.platforms)) ]); nixosModules = mapAttrs (name: path: import path) (import ./modules); overlays = { diff --git a/pkgs/build-support/aasg-brotlify/default.nix b/pkgs/build-support/aasg-brotlify/default.nix new file mode 100644 index 0000000..fed8138 --- /dev/null +++ b/pkgs/build-support/aasg-brotlify/default.nix @@ -0,0 +1,2 @@ +{ makeSetupHook, brotli, fd }: +(makeSetupHook { name = "brotlify-setup-hook.sh"; deps = [ brotli fd ]; }) ./setup-hook.sh diff --git a/pkgs/build-support/aasg-brotlify/setup-hook.sh b/pkgs/build-support/aasg-brotlify/setup-hook.sh new file mode 100644 index 0000000..8f45545 --- /dev/null +++ b/pkgs/build-support/aasg-brotlify/setup-hook.sh @@ -0,0 +1,6 @@ +postInstallHooks+=(aasg-brotlify) + +aasg-brotlify() { + if [[ -n "${dontBrotlify:-}" ]]; then return; fi + fd "" "$out" -t f -e html -e css -e js -e css.map -e js.map -X brotli --best +} diff --git a/pkgs/manifest.nix b/pkgs/manifest.nix index 35d8097..52efcaf 100644 --- a/pkgs/manifest.nix +++ b/pkgs/manifest.nix @@ -1,4 +1,5 @@ [ + [ "aasgBrotlifyHook" ] [ "dma" ] [ "drep" ] [ "dyndnsc" ] diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index fdb3bc1..56408c6 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -2,6 +2,8 @@ final: prev: { + aasgBrotlifyHook = final.callPackage ./build-support/aasg-brotlify { }; + dma = final.callPackage ./tools/networking/dma { }; drep = final.callPackage ./tools/text/drep { -- 2.45.2