haccfiles/pkgs/forgejo/default.nix
stuebinm 147fe172d9 bundle forgejo @ v7.0.2
this bundles the current package recipe of forgejo in nixpkgs-unstable.
Implies updating forgejo, since nixpkgs-stable is still on 1.20.6 (v6 in
the new version scheme).

This'll mean we have to manually update it same as with mattermost, and
can potentially also help with upstream changes. If we get tired of
that, we can always decide to just use the nixpkgs-unstable version
directly.
2024-05-16 19:06:15 +02:00

131 lines
2.9 KiB
Nix

{ bash
, brotli
, buildGoModule
, forgejo
, git
, gzip
, lib
, makeWrapper
, nix-update-script
, nixosTests
, openssh
, pam
, pamSupport ? true
, sqliteSupport ? true
, xorg
, runCommand
, stdenv
, fetchFromGitea
, buildNpmPackage
}:
let
frontend = buildNpmPackage {
pname = "forgejo-frontend";
inherit (forgejo) src version;
npmDepsHash = "sha256-BffoEbIzTU61bw3ECEm5eDHcav4S27MB5jQKsMprkcw=";
patches = [
./package-json-npm-build-frontend.patch
];
# override npmInstallHook
installPhase = ''
mkdir $out
cp -R ./public $out/
'';
};
in
buildGoModule rec {
pname = "forgejo";
version = "7.0.2";
src = fetchFromGitea {
domain = "codeberg.org";
owner = "forgejo";
repo = "forgejo";
rev = "v${version}";
hash = "sha256-YY5dHXWMqlCIPfqsDtHZLHjEdYmrFnh4yc0hfTUESww=";
};
vendorHash = "sha256-UcjaMi/4XYLdaJhi2j3UWqHqkpTbZBo6EwNXxdRIKLw=";
subPackages = [ "." ];
outputs = [ "out" "data" ];
nativeBuildInputs = [ makeWrapper ];
buildInputs = lib.optional pamSupport pam;
patches = [
./static-root-path.patch
];
postPatch = ''
substituteInPlace modules/setting/server.go --subst-var data
'';
tags = lib.optional pamSupport "pam"
++ lib.optionals sqliteSupport [ "sqlite" "sqlite_unlock_notify" ];
ldflags = [
"-s"
"-w"
"-X main.Version=${version}"
"-X 'main.Tags=${lib.concatStringsSep " " tags}'"
];
preConfigure = ''
export ldflags+=" -X main.ForgejoVersion=$(GITEA_VERSION=${version} make show-version-api)"
'';
preBuild = ''
go run build/merge-forgejo-locales.go
'';
postInstall = ''
mkdir $data
cp -R ./{templates,options} ${frontend}/public $data
mkdir -p $out
cp -R ./options/locale $out/locale
wrapProgram $out/bin/gitea \
--prefix PATH : ${lib.makeBinPath [ bash git gzip openssh ]}
'';
# $data is not available in goModules.drv and preBuild isn't needed
overrideModAttrs = (_: {
postPatch = null;
preBuild = null;
});
passthru = {
# allow nix-update to handle npmDepsHash
inherit (frontend) npmDeps;
data-compressed = runCommand "forgejo-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 = nix-update-script { };
};
meta = {
description = "A self-hosted lightweight software forge";
homepage = "https://forgejo.org";
changelog = "https://codeberg.org/forgejo/forgejo/releases/tag/${src.rev}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ emilylange urandom bendlas adamcstephens ];
broken = stdenv.isDarwin;
mainProgram = "gitea";
};
}