{ lib, buildGoModule, fetchgit, makeWrapper, git, bash, coreutils, gzip, nodejs, openssh, fetchPnpmDeps, pnpmConfigHook, pnpm, stdenv, sqliteSupport ? true, }: # Custom Gitea built from Oleks's local fork. # # Fork repo (local working copy): /home/oleks/projects/gitea # Fork remote: https://git.oleks.space/oleks/gitea.git # Tracked branch: oleks/main (the fork's integration tip; # formerly `feat/projects-api`, renamed # 2026-05-13. Carries upstream/main + # PR #37518 Projects REST API + a few # fork-local commits.) # Pin discipline: nix-update bumps `rev` and tags the fork # at `v` (see passthru.updateScript # below) so the rev stays reachable even # after future force-pushes / rebases. # # Mirrors the structure of nixpkgs' gitea derivation (frontend pnpm sub-drv # + buildGoModule with go:embed of public/) but with our fork as src. let pname = "gitea-local-fork"; version = "1.26.0-unstable-2026-05-12"; src = fetchgit { url = "https://git.oleks.space/oleks/gitea.git"; rev = "235248620e05fa4fb85ca480b0dcdc32e0f36cb5"; hash = "sha256-hh8TIjtWf2Ebw4MJSZXKXM8R3rk+h14VSk4w/SxITX8="; }; # Gitea's package.json requires pnpm >= 11; nixpkgs ships pnpm 10. The # lockfile is v9 (forward-compatible), so strip the engine constraint and # the packageManager preference before any pnpm tool sees the source. # We only patch the source the frontend sees; the Go build doesn't care. frontendSrc = stdenv.mkDerivation { pname = "${pname}-frontend-src"; inherit version src; dontConfigure = true; dontBuild = true; installPhase = '' cp -R . $out chmod -R +w $out ${nodejs}/bin/node -e ' const fs = require("fs"); const path = process.argv[1]; const pkg = JSON.parse(fs.readFileSync(path, "utf8")); if (pkg.engines) delete pkg.engines.pnpm; delete pkg.packageManager; fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n"); ' "$out/package.json" ''; }; frontend = stdenv.mkDerivation (finalAttrs: { pname = "${pname}-frontend"; inherit version; src = frontendSrc; pnpmDeps = fetchPnpmDeps { inherit (finalAttrs) pname version src; fetcherVersion = 3; hash = "sha256-Egehno2w8XyfaY+JVyVzTBlIwBpusgnMaObWNPTvh3M="; }; nativeBuildInputs = [ nodejs pnpmConfigHook pnpm ]; buildPhase = '' make frontend ''; installPhase = '' mkdir -p $out cp -R public $out/ ''; }); in buildGoModule { inherit pname version src; proxyVendor = true; vendorHash = "sha256-TxLmmeMinazGmIx94iQvpsncWKXb+42ddZcxbwayVgk="; outputs = [ "out" "data" ]; subPackages = [ "." ]; nativeBuildInputs = [ makeWrapper ]; tags = lib.optionals sqliteSupport [ "sqlite" "sqlite_unlock_notify" ]; ldflags = [ "-s" "-w" "-X main.Version=${version}" "-X 'main.Tags=${ lib.concatStringsSep " " ( lib.optionals sqliteSupport [ "sqlite" "sqlite_unlock_notify" ] ) }'" ]; postInstall = '' mkdir $data ln -s ${frontend}/public $data/public cp -R ./{templates,options} $data mkdir -p $out cp -R ./options/locale $out/locale wrapProgram $out/bin/gitea \ --prefix PATH : ${ lib.makeBinPath [ bash coreutils git gzip openssh ] } ''; passthru = { # Expose hashes nix-update needs to find when iterating. inherit (frontend) pnpmDeps; # Custom update flow: refresh hashes + retag the gitea fork + push. # Invoke with `nix-update --use-update-script gitea-local-fork` or # `just gitea-update` (which passes `--use-update-script`). updateScript = ../scripts/update-gitea-local-fork.sh; }; meta = { description = "Gitea fork with Projects REST API (upstream PR #37518)"; homepage = "https://git.oleks.space/oleks/gitea"; license = lib.licenses.mit; mainProgram = "gitea"; platforms = [ "x86_64-linux" "aarch64-linux" ]; }; }