about summary refs log tree commit diff
path: root/pkgs/applications/version-management
diff options
context:
space:
mode:
authorIzorkin <izorkin@elven.pw>2023-03-02 20:41:59 +0300
committerIzorkin <izorkin@elven.pw>2023-03-20 12:50:10 +0300
commit6b9d81b953b1dd6df343d404b322cdf72bd10e10 (patch)
treedb6d7e52913636d5a91cead68ec1520c4fbcf97b /pkgs/applications/version-management
parent57a727064266c570de636220f2f06fe859719687 (diff)
forgejo: create static gzip and brotli files
Diffstat (limited to 'pkgs/applications/version-management')
-rw-r--r--pkgs/applications/version-management/forgejo/default.nix96
1 files changed, 57 insertions, 39 deletions
diff --git a/pkgs/applications/version-management/forgejo/default.nix b/pkgs/applications/version-management/forgejo/default.nix
index 8693e6d208fad..6127aec2bbe28 100644
--- a/pkgs/applications/version-management/forgejo/default.nix
+++ b/pkgs/applications/version-management/forgejo/default.nix
@@ -1,9 +1,11 @@
 { bash
+, brotli
 , buildGoModule
 , common-updater-scripts
 , coreutils
 , curl
 , fetchurl
+, forgejo
 , git
 , gzip
 , jq
@@ -15,6 +17,8 @@
 , pam
 , pamSupport ? true
 , sqliteSupport ? true
+, xorg
+, runCommand
 , stdenv
 , writeShellApplication
 }:
@@ -66,46 +70,60 @@ buildGoModule rec {
       --prefix PATH : ${lib.makeBinPath [ bash git gzip openssh ]}
   '';
 
-  passthru.tests = nixosTests.forgejo;
-
-  passthru.updateScript = lib.getExe (writeShellApplication {
-    name = "update-forgejo";
-    runtimeInputs = [
-      common-updater-scripts
-      coreutils
-      curl
-      jq
-      nix
-    ];
-    text = ''
-      releases=$(curl "https://codeberg.org/api/v1/repos/forgejo/forgejo/releases?draft=false&pre-release=false&limit=1" \
-        --silent \
-        --header "accept: application/json")
-
-      stable=$(jq '.[0]
-        | .tag_name[1:] as $version
-        | ("forgejo-src-\($version).tar.gz") as $filename
-        | { $version, html_url } + (.assets | map(select(.name | startswith($filename)) | {(.name | split(".") | last): .browser_download_url}) | add)' \
-        <<< "$releases")
-
-      archive_url=$(jq -r .gz <<< "$stable")
-      checksum_url=$(jq -r .sha256 <<< "$stable")
-      release_url=$(jq -r .html_url <<< "$stable")
-      version=$(jq -r .version <<< "$stable")
-
-      if [[ "${version}" = "$version" ]]; then
-        echo "No new version found (already at $version)"
-        exit 0
-      fi
-
-      echo "Release: $release_url"
-
-      sha256=$(curl "$checksum_url" --silent | cut --delimiter " " --fields 1)
-      sri_hash=$(nix hash to-sri --type sha256 "$sha256")
-
-      update-source-version "${pname}" "$version" "$sri_hash" "$archive_url"
+  passthru = {
+    data-compressed = runCommand "data-compressed" {
+      nativeBuildInputs = [ brotli xorg.lndir ];
+    } ''
+      mkdir $out
+      lndir ${forgejo.data}/ $out/
+
+      # Create static gzip and brotli files
+      find -L $out -type f -regextype posix-extended -iregex '.*\.(css|html|js|svg|ttf|txt)' \
+        -exec gzip --best --keep --force {} ';' \
+        -exec brotli --best --keep --no-copy-stat {} ';'
     '';
-  });
+
+    tests = nixosTests.forgejo;
+
+    updateScript = lib.getExe (writeShellApplication {
+      name = "update-forgejo";
+      runtimeInputs = [
+        common-updater-scripts
+        coreutils
+        curl
+        jq
+        nix
+      ];
+      text = ''
+        releases=$(curl "https://codeberg.org/api/v1/repos/forgejo/forgejo/releases?draft=false&pre-release=false&limit=1" \
+          --silent \
+          --header "accept: application/json")
+
+        stable=$(jq '.[0]
+          | .tag_name[1:] as $version
+          | ("forgejo-src-\($version).tar.gz") as $filename
+          | { $version, html_url } + (.assets | map(select(.name | startswith($filename)) | {(.name | split(".") | last): .browser_download_url}) | add)' \
+          <<< "$releases")
+
+        archive_url=$(jq -r .gz <<< "$stable")
+        checksum_url=$(jq -r .sha256 <<< "$stable")
+        release_url=$(jq -r .html_url <<< "$stable")
+        version=$(jq -r .version <<< "$stable")
+
+        if [[ "${version}" = "$version" ]]; then
+          echo "No new version found (already at $version)"
+          exit 0
+        fi
+
+        echo "Release: $release_url"
+
+        sha256=$(curl "$checksum_url" --silent | cut --delimiter " " --fields 1)
+        sri_hash=$(nix hash to-sri --type sha256 "$sha256")
+
+        update-source-version "${pname}" "$version" "$sri_hash" "$archive_url"
+      '';
+    });
+  };
 
   meta = with lib; {
     description = "A self-hosted lightweight software forge";