forgejo: build from source

instead of relying on the release tarballs published with each release.
This does however add two additional hashes (`vendorHash` and `npmDepsHash`), making it a total of 3 hashes that need to be updated each time.

The old `updateScript` is no longer useful as of this change.
It was originally added because we weren't aware that gitea/forgejo/codeberg have "predictable URLs" for the needed release tarball.
Fixed in 0dd0b2103a25d2068462895faa852d535666a977

+52 -49
+38 -49
pkgs/applications/version-management/forgejo/default.nix
··· 1 1 { bash 2 2 , brotli 3 3 , buildGoModule 4 - , common-updater-scripts 5 - , coreutils 6 - , curl 7 - , fetchurl 8 4 , forgejo 9 5 , git 10 6 , gzip 11 - , jq 12 7 , lib 13 8 , makeWrapper 14 - , nix 15 9 , nixosTests 16 10 , openssh 17 11 , pam ··· 20 14 , xorg 21 15 , runCommand 22 16 , stdenv 17 + , fetchFromGitea 18 + , buildNpmPackage 23 19 , writeShellApplication 24 20 }: 25 21 22 + let 23 + frontend = buildNpmPackage rec { 24 + pname = "forgejo-frontend"; 25 + inherit (forgejo) src version; 26 + 27 + npmDepsHash = "sha256-dB/uBuS0kgaTwsPYnqklT450ejLHcPAqBdDs3JT8Uxg="; 28 + 29 + patches = [ 30 + ./package-json-npm-build-frontend.patch 31 + ]; 32 + 33 + # override npmInstallHook 34 + installPhase = '' 35 + mkdir $out 36 + cp -R ./public $out/ 37 + ''; 38 + }; 39 + in 26 40 buildGoModule rec { 27 41 pname = "forgejo"; 28 42 version = "1.19.1-0"; 29 43 30 - src = fetchurl { 31 - url = "https://codeberg.org/forgejo/forgejo/releases/download/v${version}/forgejo-src-${version}.tar.gz"; 32 - hash = "sha256-zoYEkUmJx7lt++2Rmjx/jgyZ2Y9uJH4k8VpD++My7mU="; 44 + src = fetchFromGitea { 45 + domain = "codeberg.org"; 46 + owner = "forgejo"; 47 + repo = "forgejo"; 48 + rev = "v${version}"; 49 + hash = "sha256-0FmqLxQvr3bbgdzKFeAhRMvJp/xdRPW40WLH6eKNY9s="; 33 50 }; 34 51 35 - vendorHash = null; 52 + vendorHash = "sha256-g8QJSewQFfyE/34A2JxrVnwk5vmiIRSbwrVE9LqYJrM="; 36 53 37 54 subPackages = [ "." ]; 38 55 ··· 59 76 "-X 'main.Tags=${lib.concatStringsSep " " tags}'" 60 77 ]; 61 78 79 + preBuild = '' 80 + go run build/merge-forgejo-locales.go 81 + ''; 82 + 62 83 postInstall = '' 63 84 mkdir $data 64 - cp -R ./{public,templates,options} $data 85 + cp -R ./{templates,options} ${frontend}/public $data 65 86 mkdir -p $out 66 87 cp -R ./options/locale $out/locale 67 88 wrapProgram $out/bin/gitea \ 68 89 --prefix PATH : ${lib.makeBinPath [ bash git gzip openssh ]} 69 90 ''; 70 91 92 + # $data is not available in go-modules.drv and preBuild isn't needed 93 + overrideModAttrs = (_: { 94 + postPatch = null; 95 + preBuild = null; 96 + }); 97 + 71 98 passthru = { 72 99 data-compressed = runCommand "forgejo-data-compressed" { 73 100 nativeBuildInputs = [ brotli xorg.lndir ]; ··· 82 109 ''; 83 110 84 111 tests = nixosTests.forgejo; 85 - 86 - updateScript = lib.getExe (writeShellApplication { 87 - name = "update-forgejo"; 88 - runtimeInputs = [ 89 - common-updater-scripts 90 - coreutils 91 - curl 92 - jq 93 - nix 94 - ]; 95 - text = '' 96 - releases=$(curl "https://codeberg.org/api/v1/repos/forgejo/forgejo/releases?draft=false&pre-release=false&limit=1" \ 97 - --silent \ 98 - --header "accept: application/json") 99 - 100 - stable=$(jq '.[0] 101 - | .tag_name[1:] as $version 102 - | ("forgejo-src-\($version).tar.gz") as $filename 103 - | { $version, html_url } + (.assets | map(select(.name | startswith($filename)) | {(.name | split(".") | last): .browser_download_url}) | add)' \ 104 - <<< "$releases") 105 - 106 - checksum_url=$(jq -r .sha256 <<< "$stable") 107 - release_url=$(jq -r .html_url <<< "$stable") 108 - version=$(jq -r .version <<< "$stable") 109 - 110 - if [[ "${version}" = "$version" ]]; then 111 - echo "No new version found (already at $version)" 112 - exit 0 113 - fi 114 - 115 - echo "Release: $release_url" 116 - 117 - sha256=$(curl "$checksum_url" --silent | cut --delimiter " " --fields 1) 118 - sri_hash=$(nix hash to-sri --type sha256 "$sha256") 119 - 120 - update-source-version "${pname}" "$version" "$sri_hash" 121 - ''; 122 - }); 123 112 }; 124 113 125 114 meta = with lib; {
+14
pkgs/applications/version-management/forgejo/package-json-npm-build-frontend.patch
··· 1 + diff --git a/package.json b/package.json 2 + index 57dcfc2f7..c9f23dbf7 100644 3 + --- a/package.json 4 + +++ b/package.json 5 + @@ -79,5 +79,8 @@ 6 + "defaults", 7 + "not ie > 0", 8 + "not ie_mob > 0" 9 + - ] 10 + + ], 11 + + "scripts": { 12 + + "build": "node_modules/.bin/webpack" 13 + + } 14 + }