diff --git a/pkgs/by-name/gy/gyroflow/package.nix b/pkgs/by-name/gy/gyroflow/package.nix index a3c2661c9da7..403daad8d680 100644 --- a/pkgs/by-name/gy/gyroflow/package.nix +++ b/pkgs/by-name/gy/gyroflow/package.nix @@ -1,5 +1,6 @@ { lib, + stdenv, rustPlatform, fetchFromGitHub, makeDesktopItem, @@ -10,10 +11,14 @@ qt6, alsa-lib, bash, + bzip2, ffmpeg_7, + libicns, + libxml2, mdk-sdk, ocl-icd, opencv, + zlib, }: let lens-profiles = fetchFromGitHub { @@ -38,28 +43,45 @@ rustPlatform.buildRustPackage rec { nativeBuildInputs = [ clang - copyDesktopItems - patchelf pkg-config rustPlatform.bindgenHook qt6.wrapQtAppsHook + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + copyDesktopItems + patchelf + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + libicns ]; buildInputs = [ - alsa-lib bash ffmpeg_7 mdk-sdk - ocl-icd opencv qt6.qtbase qt6.qtdeclarative qt6.qtsvg + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + alsa-lib + ocl-icd + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + bzip2 + libxml2 + zlib ]; postPatch = '' substituteInPlace build.rs \ --replace-fail 'println!("cargo:rustc-link-lib=static:+whole-archive=z")' "" + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace build.rs \ + --replace-fail 'println!("cargo:rustc-link-lib=static:+whole-archive=x264");' "" \ + --replace-fail 'println!("cargo:rustc-link-lib=static=x265");' "" ''; # qml-video-rs and gyroflow assume that all Qt headers are installed @@ -70,15 +92,29 @@ rustPlatform.buildRustPackage rec { # https://github.com/gyroflow/gyroflow/blob/v1.5.4/build.rs#L163-L186 # Additionally gyroflow needs QtQuickControls2: # https://github.com/gyroflow/gyroflow/blob/v1.5.4/build.rs#L173 - env.NIX_CFLAGS_COMPILE = toString [ - "-I${qt6.qtdeclarative}/include/QtQuick" - "-I${qt6.qtdeclarative}/include/QtQuick/${qt6.qtdeclarative.version}" - "-I${qt6.qtdeclarative}/include/QtQuick/${qt6.qtdeclarative.version}/QtQuick" - "-I${qt6.qtdeclarative}/include/QtQml" - "-I${qt6.qtdeclarative}/include/QtQml/${qt6.qtdeclarative.version}" - "-I${qt6.qtdeclarative}/include/QtQml/${qt6.qtdeclarative.version}/QtQml" - "-I${qt6.qtdeclarative}/include/QtQuickControls2" - ]; + env.NIX_CFLAGS_COMPILE = toString ( + if stdenv.hostPlatform.isDarwin then + [ + "-F${qt6.qtdeclarative}/lib" + "-I${qt6.qtdeclarative}/lib/QtQuick.framework/Headers" + "-I${qt6.qtdeclarative}/lib/QtQuick.framework/Headers/${qt6.qtdeclarative.version}" + "-I${qt6.qtdeclarative}/lib/QtQuick.framework/Headers/${qt6.qtdeclarative.version}/QtQuick" + "-I${qt6.qtdeclarative}/lib/QtQml.framework/Headers" + "-I${qt6.qtdeclarative}/lib/QtQml.framework/Headers/${qt6.qtdeclarative.version}" + "-I${qt6.qtdeclarative}/lib/QtQml.framework/Headers/${qt6.qtdeclarative.version}/QtQml" + "-I${qt6.qtdeclarative}/lib/QtQuickControls2.framework/Headers" + ] + else + [ + "-I${qt6.qtdeclarative}/include/QtQuick" + "-I${qt6.qtdeclarative}/include/QtQuick/${qt6.qtdeclarative.version}" + "-I${qt6.qtdeclarative}/include/QtQuick/${qt6.qtdeclarative.version}/QtQuick" + "-I${qt6.qtdeclarative}/include/QtQml" + "-I${qt6.qtdeclarative}/include/QtQml/${qt6.qtdeclarative.version}" + "-I${qt6.qtdeclarative}/include/QtQml/${qt6.qtdeclarative.version}/QtQml" + "-I${qt6.qtdeclarative}/include/QtQuickControls2" + ] + ); # FFMPEG_DIR is used by ffmpeg-sys-next/build.rs and # gyroflow/build.rs. ffmpeg-sys-next fails to build if this dir @@ -102,23 +138,69 @@ rustPlatform.buildRustPackage rec { doCheck = false; # No tests. - postInstall = '' - mkdir -p $out/opt/Gyroflow - cp -r resources $out/opt/Gyroflow/ - ln -s ${lens-profiles} $out/opt/Gyroflow/resources/camera_presets + # mdk-sdk license key is hardcoded to 'gyroflow' process name, wrapQt changes it, + # which breaks the license check and throws a QR code + dontWrapQtApps = true; - rm -rf $out/lib - patchelf $out/bin/gyroflow --add-rpath ${mdk-sdk}/lib + postInstall = + if stdenv.hostPlatform.isDarwin then + '' + contents=$out/Applications/Gyroflow.app/Contents - mv $out/bin/gyroflow $out/opt/Gyroflow/ - ln -s ../opt/Gyroflow/gyroflow $out/bin/ + mkdir -p $out/Applications + cp -r _deployment/mac/Gyroflow.app $out/Applications/ + find $out/Applications/Gyroflow.app -name .empty -delete - install -D ${./gyroflow-open.sh} $out/bin/gyroflow-open - install -Dm644 ${./gyroflow-mime.xml} $out/share/mime/packages/gyroflow.xml - install -Dm644 resources/icon.svg $out/share/icons/hicolor/scalable/apps/gyroflow.svg - ''; + # Qt is located through wrapQtAppsHook, so drop upstream's qt.conf, + # which points plugin and QML lookups back inside the bundle. + rm $contents/Resources/qt.conf - desktopItems = [ + substituteInPlace $contents/Info.plist \ + --replace-fail \ + 'CFBundleExecutable gyroflow' \ + 'CFBundleExecutable gyroflow-launcher' + + png2icns $contents/Resources/AppIcon.icns resources/icon_1024_mac.png + + ln -s ${lens-profiles} $contents/Resources/camera_presets + + install_name_tool -add_rpath ${mdk-sdk}/lib $out/bin/gyroflow + mv $out/bin/gyroflow $contents/MacOS/gyroflow + rmdir $out/bin + + rm -rf $out/lib + '' + else + '' + mkdir -p $out/opt/Gyroflow + cp -r resources $out/opt/Gyroflow/ + ln -s ${lens-profiles} $out/opt/Gyroflow/resources/camera_presets + + rm -rf $out/lib + patchelf $out/bin/gyroflow --add-rpath ${mdk-sdk}/lib + + mv $out/bin/gyroflow $out/opt/Gyroflow/ + + install -D ${./gyroflow-open.sh} $out/bin/gyroflow-open + install -Dm644 ${./gyroflow-mime.xml} $out/share/mime/packages/gyroflow.xml + install -Dm644 resources/icon.svg $out/share/icons/hicolor/scalable/apps/gyroflow.svg + ''; + + postFixup = + if stdenv.hostPlatform.isDarwin then + '' + macos=$out/Applications/Gyroflow.app/Contents/MacOS + makeQtWrapper $macos/gyroflow $macos/gyroflow-launcher + + mkdir -p $out/bin + ln -s ../Applications/Gyroflow.app/Contents/MacOS/gyroflow-launcher $out/bin/gyroflow + '' + else + '' + makeQtWrapper $out/opt/Gyroflow/gyroflow $out/bin/gyroflow + ''; + + desktopItems = lib.optionals stdenv.hostPlatform.isLinux [ (makeDesktopItem { name = "gyroflow"; desktopName = "Gyroflow"; @@ -148,6 +230,9 @@ rustPlatform.buildRustPackage rec { cc0 ]; maintainers = [ ]; - platforms = [ "x86_64-linux" ]; + platforms = [ + "aarch64-darwin" + "x86_64-linux" + ]; }; }