From 44fec1f60218d1798be104a8e8b31774815d37f3 Mon Sep 17 00:00:00 2001
From: fbettag <franz@bett.ag>
Date: Thu, 31 Oct 2024 12:03:28 +0100
Subject: [PATCH] jameica: add `arch64-darwin` support

---
 pkgs/applications/office/jameica/default.nix | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pkgs/applications/office/jameica/default.nix b/pkgs/applications/office/jameica/default.nix
index 32cbcf088c51..3f9e20d7a042 100644
--- a/pkgs/applications/office/jameica/default.nix
+++ b/pkgs/applications/office/jameica/default.nix
@@ -24,6 +24,7 @@ let
     else if stdenv.hostPlatform.system == "x86_64-linux" then "linux64"
     else if stdenv.hostPlatform.system == "aarch64-linux" then "linux-arm64"
     else if stdenv.hostPlatform.system == "x86_64-darwin" then "macos64"
+    else if stdenv.hostPlatform.system == "aarch64-darwin" then "macos-aarch64"
     else throw "Unsupported system: ${stdenv.hostPlatform.system}";
 
   desktopItem = makeDesktopItem {
@@ -57,7 +58,7 @@ stdenv.mkDerivation rec {
   # and is not able to build the application itself
   buildPhase = ''
     runHook preBuild
-    ant -f build -Dsystem.version=${version} init compile jar
+    ant -f build -Dsystem.version=${version} init compile jar ${lib.optionalString stdenv.hostPlatform.isDarwin "zip lib"}
     runHook postBuild
   '';
 
@@ -75,6 +76,13 @@ stdenv.mkDerivation rec {
     install -Dm644 plugin.xml $out/share/java/
     install -Dm644 build/jameica-icon.png $out/share/pixmaps/jameica.png
     cp ${desktopItem}/share/applications/* $out/share/applications/
+  '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
+
+    # Create .app bundle for macOS
+    mkdir -p $out/Applications
+    chmod +x releases/${_version}-${_build}-${_build}/tmp/jameica.app/jameica*.sh
+    cp -r releases/${_version}-${_build}-${_build}/tmp/jameica.app $out/Applications/Jameica.app
+  '' + ''
 
     runHook postInstall
   '';
@@ -101,7 +109,7 @@ stdenv.mkDerivation rec {
       binaryBytecode # source bundles dependencies as jars
     ];
     license = licenses.gpl2Plus;
-    platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" ];
+    platforms = platforms.unix;
     maintainers = with maintainers; [ flokli r3dl3g ];
     mainProgram = "jameica";
   };