From 68c50246016d14ed2aa21d6744ef39229494cbee Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Wed, 2 Jul 2025 21:36:00 +0200 Subject: [PATCH] tenacity: add darwin support --- pkgs/by-name/te/tenacity/package.nix | 60 +++++++++++++++++++++------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/pkgs/by-name/te/tenacity/package.nix b/pkgs/by-name/te/tenacity/package.nix index 509290301648..31fb7c07b743 100644 --- a/pkgs/by-name/te/tenacity/package.nix +++ b/pkgs/by-name/te/tenacity/package.nix @@ -3,6 +3,7 @@ lib, fetchFromGitea, cmake, + ninja, wxGTK32, gtk3, pkg-config, @@ -60,16 +61,42 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-2gndOwgEJK2zDSbjcZigbhEpGv301/ygrf+EQhKp8PI="; }; - postPatch = '' - mkdir -p build/src/private - touch build/src/private/RevisionIdent.h + postPatch = + '' + # GIT_DESCRIBE is used for the version string and can't be passed in + # as an option, so we substitute it instead. + substituteInPlace CMakeLists.txt \ + --replace-fail 'set( GIT_DESCRIBE "unknown" )' 'set( GIT_DESCRIBE "${finalAttrs.version}" )' + '' + + lib.optionalString stdenv.hostPlatform.isLinux '' + substituteInPlace libraries/lib-files/FileNames.cpp \ + --replace-fail /usr/include/linux/magic.h ${linuxHeaders}/include/linux/magic.h + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + # Tenacity has special handling for ffmpeg library search on darwin, + # looking only in a few specific directories. + # Make sure it searches for our version of ffmpeg in the nix store. + substituteInPlace libraries/lib-ffmpeg-support/FFmpegFunctions.cpp \ + --replace-fail /usr/local/lib/tenacity ${lib.getLib ffmpeg}/lib + ''; - substituteInPlace libraries/lib-files/FileNames.cpp \ - --replace /usr/include/linux/magic.h \ - ${linuxHeaders}/include/linux/magic.h + postInstall = lib.optionalString stdenv.hostPlatform.isDarwin '' + mkdir $out/{bin,Applications} + mv $out/{,Applications/}Tenacity.app + + # Symlinking the binary is insufficient as it would be unable to + # find the bundle resources + cat << EOF > "$out/bin/tenacity" + #!${stdenv.shell} + open -na "$out/Applications/Tenacity.app" --args "\$@" + EOF + chmod +x "$out/bin/tenacity" + + # Only contains a static library that is already linked into the tenacity binary + rm -r $out/lib ''; - postFixup = '' + postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' wrapProgram "$out/bin/tenacity" \ --suffix AUDACITY_PATH : "$out/share/tenacity" \ --suffix AUDACITY_MODULES_PATH : "$out/lib/tenacity/modules" \ @@ -77,10 +104,9 @@ stdenv.mkDerivation (finalAttrs: { --prefix XDG_DATA_DIRS : "$out/share:$GSETTINGS_SCHEMAS_PATH" ''; - env.NIX_CFLAGS_COMPILE = "-D GIT_DESCRIBE=\"\""; - - # tenacity only looks for ffmpeg at runtime, so we need to link it in manually - NIX_LDFLAGS = toString [ + # Tenacity only looks for ffmpeg at runtime, so we need to link it in manually. + # On darwin, these are ignored by the ffmpeg search even when linked. + NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux (toString [ "-lavcodec" "-lavdevice" "-lavfilter" @@ -89,23 +115,23 @@ stdenv.mkDerivation (finalAttrs: { "-lpostproc" "-lswresample" "-lswscale" - ]; + ]); nativeBuildInputs = [ cmake + ninja gettext - makeWrapper pkg-config python3 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ + makeWrapper linuxHeaders ]; buildInputs = [ - alsa-lib expat ffmpeg file @@ -134,6 +160,7 @@ stdenv.mkDerivation (finalAttrs: { gtk3 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ + alsa-lib at-spi2-core dbus libepoxy @@ -149,6 +176,9 @@ stdenv.mkDerivation (finalAttrs: { cmakeFlags = [ # RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/ "-DCMAKE_SKIP_BUILD_RPATH=ON" + # Disabled by default on Linux but enabled on Darwin, so we disable it explicitly for all platforms, + # as we provide dependencies from nixpkgs regardless of the target platform. + "-DVCPKG=OFF" ]; meta = { @@ -157,6 +187,6 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://tenacityaudio.org/"; license = lib.licenses.gpl2Plus; maintainers = with lib.maintainers; [ irenes ]; - platforms = lib.platforms.linux; + platforms = lib.platforms.unix; }; })