about summary refs log tree commit diff
path: root/pkgs/by-name/fo
diff options
context:
space:
mode:
authorWeijia Wang <9713184+wegank@users.noreply.github.com>2024-04-27 05:44:19 +0200
committerWeijia Wang <9713184+wegank@users.noreply.github.com>2024-04-27 05:44:19 +0200
commit37876dbdadca20702d3547bab7838fa4ca1bae33 (patch)
tree92efdc055a9cd4e4c680a32d4a0492e8a2e11855 /pkgs/by-name/fo
parent2521336f17c46069cb8fbba200974fcc12e9ea9d (diff)
parent86aa70f787d423141167d1cde8af6d81126e22a1 (diff)
Merge branch 'master' into staging-next
Diffstat (limited to 'pkgs/by-name/fo')
-rw-r--r--pkgs/by-name/fo/forgejo/package-json-npm-build-frontend.patch14
-rw-r--r--pkgs/by-name/fo/forgejo/package.nix131
-rw-r--r--pkgs/by-name/fo/forgejo/static-root-path.patch13
3 files changed, 158 insertions, 0 deletions
diff --git a/pkgs/by-name/fo/forgejo/package-json-npm-build-frontend.patch b/pkgs/by-name/fo/forgejo/package-json-npm-build-frontend.patch
new file mode 100644
index 0000000000000..f7567da020c63
--- /dev/null
+++ b/pkgs/by-name/fo/forgejo/package-json-npm-build-frontend.patch
@@ -0,0 +1,14 @@
+diff --git a/package.json b/package.json
+index b50c52cf43..d6aafb8775 100644
+--- a/package.json
++++ b/package.json
+@@ -98,5 +98,8 @@
+   },
+   "browserslist": [
+     "defaults"
+-  ]
++  ],
++  "scripts": {
++    "build": "node_modules/.bin/webpack"
++  }
+ }
diff --git a/pkgs/by-name/fo/forgejo/package.nix b/pkgs/by-name/fo/forgejo/package.nix
new file mode 100644
index 0000000000000..fca06c86646dc
--- /dev/null
+++ b/pkgs/by-name/fo/forgejo/package.nix
@@ -0,0 +1,131 @@
+{ 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.0";
+
+  src = fetchFromGitea {
+    domain = "codeberg.org";
+    owner = "forgejo";
+    repo = "forgejo";
+    rev = "v${version}";
+    hash = "sha256-oIx1aPrHgOWx13ocA3t7N5UdTgr+64tgC0XcEnhA/eE=";
+  };
+
+  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";
+  };
+}
diff --git a/pkgs/by-name/fo/forgejo/static-root-path.patch b/pkgs/by-name/fo/forgejo/static-root-path.patch
new file mode 100644
index 0000000000000..598c3a8103b1d
--- /dev/null
+++ b/pkgs/by-name/fo/forgejo/static-root-path.patch
@@ -0,0 +1,13 @@
+diff --git a/modules/setting/server.go b/modules/setting/server.go
+index c20dd1949d..c9bcdce99a 100644
+--- a/modules/setting/server.go
++++ b/modules/setting/server.go
+@@ -317,7 +317,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
+ 	RedirectorUseProxyProtocol = sec.Key("REDIRECTOR_USE_PROXY_PROTOCOL").MustBool(UseProxyProtocol)
+ 	OfflineMode = sec.Key("OFFLINE_MODE").MustBool(true)
+ 	if len(StaticRootPath) == 0 {
+-		StaticRootPath = AppWorkPath
++		StaticRootPath = "@data@"
+ 	}
+ 	StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath)
+ 	StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)