From 56ea501f3bae76e95d20268b700800121f70b47d Mon Sep 17 00:00:00 2001 From: winston Date: Sat, 11 Jul 2026 13:26:02 +0100 Subject: [PATCH] opentrack: add macOS support --- pkgs/by-name/op/opentrack/package.nix | 83 ++++++++++++++++--- .../opentrack/remove_app_bundle_script.patch | 15 ++++ 2 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 pkgs/by-name/op/opentrack/remove_app_bundle_script.patch diff --git a/pkgs/by-name/op/opentrack/package.nix b/pkgs/by-name/op/opentrack/package.nix index 044532e6555c..ed9562e740cc 100644 --- a/pkgs/by-name/op/opentrack/package.nix +++ b/pkgs/by-name/op/opentrack/package.nix @@ -12,8 +12,11 @@ opencv4, procps, eigen, + imagemagick, libxdmcp, libevdev, + libicns, + llvmPackages, makeDesktopItem, wineWow64Packages, onnxruntime, @@ -21,6 +24,9 @@ v4l-utils, withWine ? stdenv.targetPlatform.isx86_64, }: +let + inherit (stdenv.hostPlatform) isLinux isDarwin; +in stdenv.mkDerivation (finalAttrs: { pname = "opentrack"; version = "2026.1.0-unstable-2026-07-09"; @@ -51,6 +57,8 @@ stdenv.mkDerivation (finalAttrs: { patches = [ # calls `app.setDesktopFileName("opentrack");` - distros that don't wrap the binary apparently don't need this. ./desktop-filename.patch + # disables the upstream macOS .app artifact script + ./remove_app_bundle_script.patch ]; strictDeps = true; @@ -62,40 +70,89 @@ stdenv.mkDerivation (finalAttrs: { pkg-config qt6.wrapQtAppsHook ] + ++ lib.optionals isDarwin [ + libicns + imagemagick + ] ++ lib.optionals withWine [ wineWow64Packages.stable ]; buildInputs = [ - finalAttrs.aruco eigen libxdmcp - libevdev onnxruntime opencv4 procps qt6.qtbase qt6.qttools - ]; + ] + ++ lib.optionals isLinux [ + finalAttrs.aruco + libevdev + ] + ++ lib.optionals isDarwin [ + qt6.qtmultimedia + ] + # is available-by-default on gcc + ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ]; cmakeFlags = [ (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_AHRSFUSION" "${finalAttrs.fusion}") (lib.cmakeFeature "OPENTRACK_COMMIT" "opentrack-${finalAttrs.version}") (lib.cmakeBool "SDK_WINE" withWine) - (lib.cmakeFeature "SDK_ARUCO_LIBPATH" "${finalAttrs.aruco}/lib/libaruco.a") (lib.cmakeFeature "SDK_XPLANE" finalAttrs.xplaneSdk.outPath) + ] + ++ lib.optionals isLinux [ + (lib.cmakeFeature "SDK_ARUCO_LIBPATH" "${finalAttrs.aruco}/lib/libaruco.a") ]; - postInstall = '' - install -Dt $out/share/icons/hicolor/256x256/apps ../gui/images/opentrack.png - ''; + postInstall = + lib.optionalString isLinux '' + install -Dt $out/share/icons/hicolor/256x256/apps ../gui/images/opentrack.png + '' + + lib.optionalString isDarwin '' + mkdir -p $out/Applications + mv $out/opentrack.app $out/Applications/ + + chmod -R +w "$out/Applications/opentrack.app" + + # use upstream Info.plist for correct permissions etc. + cp "../macosx/Info.plist" "$out/Applications/opentrack.app/Contents/" + substituteInPlace "$out/Applications/opentrack.app/Contents/Info.plist" \ + --subst-var-by "OPENTRACK-VERSION" "${finalAttrs.version}" + + cp "../macosx/PkgInfo" "$out/Applications/opentrack.app/Contents/" + mv "$out/Plugins" "$out/Applications/opentrack.app/Contents/MacOS/Plugins" + + # create the macOS iconset + tmp="$(mktemp -d)" + files="" + for size in 16 32 64 128 256 512; do + outfile="$tmp/opentrack_''${size}x''${size}.png" + magick "../gui/images/opentrack.png" -filter triangle -resize "''${size}x''${size}" "$outfile" + files="$files $outfile" + done + png2icns "$out/Applications/opentrack.app/Contents/Resources/opentrack.icns" $files + rm -rf "$tmp" + ''; # manually wrap just the main binary dontWrapQtApps = true; - preFixup = '' - wrapQtApp $out/bin/opentrack \ - --prefix PATH : ${lib.makeBinPath [ v4l-utils ]} - ''; + qtWrapperArgs = + lib.optionals isLinux [ + "--prefix PATH : ${lib.makeBinPath [ v4l-utils ]}" + ] + ++ lib.optionals isDarwin [ + "--set DYLD_LIBRARY_PATH ${placeholder "out"}/Library" + ]; + preFixup = + lib.optionalString isLinux '' + wrapQtApp $out/bin/opentrack + '' + + lib.optionalString isDarwin '' + wrapQtApp $out/Applications/opentrack.app/Contents/MacOS/opentrack + ''; - desktopItems = [ + desktopItems = lib.optionals isLinux [ (makeDesktopItem { name = "opentrack"; exec = "opentrack"; @@ -124,6 +181,6 @@ stdenv.mkDerivation (finalAttrs: { lib.maintainers.nekowinston lib.maintainers.zaninime ]; - platforms = lib.platforms.linux; + platforms = lib.platforms.unix; }; }) diff --git a/pkgs/by-name/op/opentrack/remove_app_bundle_script.patch b/pkgs/by-name/op/opentrack/remove_app_bundle_script.patch new file mode 100644 index 000000000000..74793134fa39 --- /dev/null +++ b/pkgs/by-name/op/opentrack/remove_app_bundle_script.patch @@ -0,0 +1,15 @@ +diff --git a/macosx/CMakeLists.txt b/macosx/CMakeLists.txt +index 8520e9e9..6428e91e 100644 +--- a/macosx/CMakeLists.txt ++++ b/macosx/CMakeLists.txt +@@ -2,10 +2,4 @@ if(APPLE) + otr_escape_string(srcdir "${CMAKE_SOURCE_DIR}") + otr_escape_string(instdir "${CMAKE_INSTALL_PREFIX}") + otr_escape_string(commit "${OPENTRACK_COMMIT}") +- install(CODE " +- execute_process(COMMAND /bin/sh \"${srcdir}/macosx/make-app-bundle.sh\" +- \"${srcdir}/macosx\" +- \"${instdir}\" +- \"${commit}\") +- ") + endif()