From e4fa6645f1d1429f20086542cd76d98d974cf29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 22 Aug 2024 13:08:53 +0300 Subject: [PATCH] compressDrv: use upstream --- flake.nix | 5 -- hosts/fwminex/configuration.nix | 2 +- modules/profiles/desktop/default.nix | 1 + modules/services/gitea/default.nix | 2 +- pkgs/compress-drv/default.nix | 63 ----------------- pkgs/compress-drv/test.nix | 42 ----------- pkgs/compress-drv/web.nix | 102 --------------------------- statix.toml | 9 --- 8 files changed, 3 insertions(+), 223 deletions(-) delete mode 100644 pkgs/compress-drv/default.nix delete mode 100644 pkgs/compress-drv/test.nix delete mode 100644 pkgs/compress-drv/web.nix diff --git a/flake.nix b/flake.nix index a3dd5a5..93c0654 100644 --- a/flake.nix +++ b/flake.nix @@ -94,9 +94,6 @@ deploy-rs-pkg = null; }) (_: super: { - compressDrv = super.callPackage ./pkgs/compress-drv { }; - compressDrvWeb = super.callPackage ./pkgs/compress-drv/web.nix { }; - nicer = super.callPackage ./pkgs/nicer.nix { }; tmuxbash = super.callPackage ./pkgs/tmuxbash.nix { }; vanta-agent = super.callPackage ./pkgs/vanta-agent.nix { }; @@ -351,8 +348,6 @@ statix.enable = true; }; }; - - compress-drv-test = pkgs.callPackage ./pkgs/compress-drv/test.nix { }; } ) deploy-rs.lib; } diff --git a/hosts/fwminex/configuration.nix b/hosts/fwminex/configuration.nix index 35a142c..f281029 100644 --- a/hosts/fwminex/configuration.nix +++ b/hosts/fwminex/configuration.nix @@ -217,7 +217,7 @@ in ''; "irc.jakstys.lt".extraConfig = let - gamja = pkgs.compressDrvWeb (pkgs.gamja.override { + gamja = pkgs.pkgs-unstable.compressDrvWeb (pkgs.gamja.override { gamjaConfig = { server = { url = "irc.jakstys.lt:6698"; diff --git a/modules/profiles/desktop/default.nix b/modules/profiles/desktop/default.nix index 79238c5..241822a 100644 --- a/modules/profiles/desktop/default.nix +++ b/modules/profiles/desktop/default.nix @@ -171,6 +171,7 @@ in neomutt picocom inferno + libheif inkscape chromium hunspell diff --git a/modules/services/gitea/default.nix b/modules/services/gitea/default.nix index f6a8bb7..1a02463 100644 --- a/modules/services/gitea/default.nix +++ b/modules/services/gitea/default.nix @@ -80,7 +80,7 @@ route /static/assets/* { uri strip_prefix /static file_server * { - root ${pkgs.compressDrvWeb pkgs.gitea.data { }}/public + root ${pkgs.pkgs-unstable.compressDrvWeb pkgs.gitea.data { }}/public precompressed br gzip } } diff --git a/pkgs/compress-drv/default.nix b/pkgs/compress-drv/default.nix deleted file mode 100644 index e5736b1..0000000 --- a/pkgs/compress-drv/default.nix +++ /dev/null @@ -1,63 +0,0 @@ -/* - compressDrv compresses files in a given derivation. - - Inputs: - - - formats :: [String] - - List of file extensions to compress. - - Example: ["txt" "svg" "xml"] - - - compressors :: {String -> String} - - Map a desired extension (e.g. `gz`) to a compress program. - - The compressor program that will be executed to get the `COMPRESSOR` - extension. The program should have a single " {}", which will be the - replaced with the target filename. - - Compressor must: - - read symlinks (thus --force is needed to gzip, zstd, xz). - - keep the original file in place (--keep). - - Example: - - { - xz = "${xz}/bin/xz --force --keep {}"; - } - - See compressDrvWeb, which is a wrapper on top of compressDrv, for broader - use examples. -*/ -{ - lib, - xorg, - runCommand, -}: -drv: -{ formats, compressors }: -let - validProg = - ext: prog: - let - matches = (builtins.length (builtins.split "\\{}" prog) - 1) / 2; - in - lib.assertMsg ( - matches == 1 - ) "compressor ${ext} needs to have exactly one '{}', found ${builtins.toString matches}"; - mkCmd = - ext: prog: - assert validProg ext prog; - '' - find -L $out -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})' -print0 \ - | xargs -0 -P$NIX_BUILD_CORES -I{} ${prog} - ''; - formatsPipe = builtins.concatStringsSep "|" formats; -in -runCommand "${drv.name}-compressed" { } '' - mkdir $out - (cd $out; ${xorg.lndir}/bin/lndir ${drv}) - - ${lib.concatStringsSep "\n\n" (lib.mapAttrsToList mkCmd compressors)} -'' diff --git a/pkgs/compress-drv/test.nix b/pkgs/compress-drv/test.nix deleted file mode 100644 index 74cc8c4..0000000 --- a/pkgs/compress-drv/test.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ - gzip, - runCommand, - compressDrv, -}: -let - example = runCommand "sample-drv" { } '' - mkdir $out - echo 42 > $out/1.txt - echo 43 > $out/1.md - touch $out/2.png - ''; - drv = compressDrv example { - formats = [ "txt" ]; - compressors.gz = "${gzip}/bin/gzip --force --keep --fast {}"; - }; - wrapped = compressDrv drv { - formats = [ "md" ]; - compressors.gz = "${gzip}/bin/gzip --force --keep --fast {}"; - }; -in -runCommand "test-compressDrv" { } '' - set -ex - - ls -l ${drv} - test -h ${drv}/1.txt - test -f ${drv}/1.txt.gz - cmp ${drv}/1.txt <(${gzip}/bin/zcat ${drv}/1.txt.gz) - - test -h ${drv}/2.png - test ! -a ${drv}/2.png.gz - - # compressDrv always points to the final file, no matter how many times - # it's been wrapped - cmp <(readlink -e ${drv}/1.txt) <(readlink -e ${wrapped}/1.txt) - - test -f ${wrapped}/1.txt.gz - test -f ${wrapped}/1.md.gz - test ! -f ${drv}/1.md.gz - - mkdir $out -'' diff --git a/pkgs/compress-drv/web.nix b/pkgs/compress-drv/web.nix deleted file mode 100644 index 3789b94..0000000 --- a/pkgs/compress-drv/web.nix +++ /dev/null @@ -1,102 +0,0 @@ -/* - compressDrvWeb compresses a derivation for common web server use. - - Useful when one wants to pre-compress certain static assets and pass them to - the web server. For example, `pkgs.gamja` creates this derivation: - - /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/ - ├── index.2fd01148.js - ├── index.2fd01148.js.map - ├── index.37aa9a8a.css - ├── index.37aa9a8a.css.map - ├── index.html - └── manifest.webmanifest - - `pkgs.compressDrvWeb pkgs.gamja`: - - /nix/store/f5ryid7zrw2hid7h9kil5g5j29q5r2f7-gamja-1.0.0-beta.9-compressed - ├── index.2fd01148.js -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js - ├── index.2fd01148.js.br - ├── index.2fd01148.js.gz - ├── index.2fd01148.js.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js.map - ├── index.2fd01148.js.map.br - ├── index.2fd01148.js.map.gz - ├── index.37aa9a8a.css -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css - ├── index.37aa9a8a.css.br - ├── index.37aa9a8a.css.gz - ├── index.37aa9a8a.css.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css.map - ├── index.37aa9a8a.css.map.br - ├── index.37aa9a8a.css.map.gz - ├── index.html -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.html - ├── index.html.br - ├── index.html.gz - ├── manifest.webmanifest -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/manifest.webmanifest - ├── manifest.webmanifest.br - └── manifest.webmanifest.gz - - When this `-compressed` directory is passed to a properly configured web - server, it will serve those pre-compressed files: - - $ curl -I -H 'Accept-Encoding: br' https://irc.example.org/ - <...> - content-encoding: br - <...> - - For example, a caddy configuration snippet for gamja to serve - the static assets (JS, CSS files) pre-compressed: - - virtualHosts."irc.example.org".extraConfig = '' - root * ${pkgs.compressDrvWeb pkgs.gamja {}} - file_server browse { - precompressed br gzip - } - ''; - - This feature is also available in nginx via `ngx_brotli` and - `ngx_http_gzip_static_module`. - - Inputs: - - formats :: [String] - - List of file extensions to compress. - - Default: common formats that compress well. The list may be expanded. - - - extraFormats :: [String] - - Extra extensions to compress in addition to `formats`. - - - compressors :: {String -> String} - - See parameter `compressors` of compressDrv. -*/ -{ - zopfli, - brotli, - compressDrv, -}: -drv: -{ - formats ? [ - "css" - "js" - "svg" - "ttf" - "eot" - "txt" - "xml" - "map" - "html" - "json" - "webmanifest" - ], - extraFormats ? [ ], - compressors ? { - "gz" = "${zopfli}/bin/zopfli --keep {}"; - "br" = "${brotli}/bin/brotli --keep --no-copy-stat {}"; - }, -}: -compressDrv drv { - formats = formats ++ extraFormats; - compressors = compressors; -} diff --git a/statix.toml b/statix.toml index 4ac04ee..3570589 100644 --- a/statix.toml +++ b/statix.toml @@ -1,11 +1,2 @@ ignore = ['modules/base/boot'] - -# If the attrset has an optional field, `inherit` will not inherit it: -# compressDrvWeb = drv: { -# compressors ? ["gz" "br"], -# ... -# } @ args: -# compressDrv drv { -# inherit (compressors) <<- function 'compressDrv' called without required argument 'compressors' -# } disabled = ["manual_inherit", "manual_inherit_from"]