From d5d40a37e6eeaf7088064c39dd019c514e32cb1f Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sat, 21 Dec 2024 17:04:56 +0000 Subject: [PATCH] 3p/nixpkgs: aja --- .../video/obs-studio/CMakeUserPresets.json | 17 +++ .../applications/video/obs-studio/default.nix | 29 +++- .../aj/aja-desktop-software/package.nix | 126 ++++++++++++++++++ .../li/libajantv2/device-info-list.patch | 13 ++ .../pkgs/by-name/li/libajantv2/package.nix | 38 ++++-- .../li/libajantv2/use-system-mbedtls.patch | 86 ++++++++++++ .../development/libraries/libcef/default.nix | 9 +- .../os-specific/linux/ajantv2/default.nix | 41 ++++++ .../nixpkgs/pkgs/top-level/linux-kernels.nix | 2 + 9 files changed, 342 insertions(+), 19 deletions(-) create mode 100644 third_party/nixpkgs/pkgs/applications/video/obs-studio/CMakeUserPresets.json create mode 100644 third_party/nixpkgs/pkgs/by-name/aj/aja-desktop-software/package.nix create mode 100644 third_party/nixpkgs/pkgs/by-name/li/libajantv2/device-info-list.patch create mode 100644 third_party/nixpkgs/pkgs/by-name/li/libajantv2/use-system-mbedtls.patch create mode 100644 third_party/nixpkgs/pkgs/os-specific/linux/ajantv2/default.nix diff --git a/third_party/nixpkgs/pkgs/applications/video/obs-studio/CMakeUserPresets.json b/third_party/nixpkgs/pkgs/applications/video/obs-studio/CMakeUserPresets.json new file mode 100644 index 0000000000..932ca674c0 --- /dev/null +++ b/third_party/nixpkgs/pkgs/applications/video/obs-studio/CMakeUserPresets.json @@ -0,0 +1,17 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "nixpkgs-linux", + "displayName": "Nixpkgs (Linux)", + "inherits": ["ubuntu"], + "binaryDir": "${sourceDir}/build" + }, + { + "name": "nixpkgs-darwin", + "displayName": "Nixpkgs (Darwin)", + "inherits": ["macos"], + "binaryDir": "${sourceDir}/build" + } + ] +} diff --git a/third_party/nixpkgs/pkgs/applications/video/obs-studio/default.nix b/third_party/nixpkgs/pkgs/applications/video/obs-studio/default.nix index 5dff164084..78974b91ac 100644 --- a/third_party/nixpkgs/pkgs/applications/video/obs-studio/default.nix +++ b/third_party/nixpkgs/pkgs/applications/video/obs-studio/default.nix @@ -2,6 +2,7 @@ , uthash , lib , stdenv +, ninja , nv-codec-headers-12 , fetchFromGitHub , fetchpatch @@ -51,6 +52,8 @@ , asio , decklinkSupport ? false , blackmagic-desktop-video +, ajaSupport ? false +, libajantv2 , libdatachannel , libvpl , qrcodegencpp @@ -107,6 +110,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ addDriverRunpath cmake + ninja pkg-config wrapGAppsHook3 wrapQtAppsHook @@ -148,7 +152,8 @@ stdenv.mkDerivation (finalAttrs: { ++ optional alsaSupport alsa-lib ++ optional pulseaudioSupport libpulseaudio ++ optionals pipewireSupport [ pipewire libdrm ] - ++ optional withFdk fdk_aac; + ++ optional withFdk fdk_aac + ++ optional ajaSupport libajantv2; # Copied from the obs-linuxbrowser postUnpack = '' @@ -157,16 +162,22 @@ stdenv.mkDerivation (finalAttrs: { ln -s $i cef/Release/ ln -s $i cef/Resources/ done - ln -s ${libcef}/lib/libcef.so cef/Release/ + ln -s ${libcef}/lib/*.so* cef/Release/ + ln -s ${libcef}/libexec/cef/chrome-sandbox cef/Release/ ln -s ${libcef}/lib/libcef_dll_wrapper.a cef/libcef_dll_wrapper/ ln -s ${libcef}/include cef/ ''; + postPatch = '' + cp ${./CMakeUserPresets.json} ./CMakeUserPresets.json + ''; + cmakeFlags = [ + "--preset" "nixpkgs-${if stdenv.hostPlatform.isDarwin then "darwin" else "linux"}" "-DOBS_VERSION_OVERRIDE=${finalAttrs.version}" "-Wno-dev" # kill dev warnings that are useless for packaging # Add support for browser source - "-DBUILD_BROWSER=ON" + "-DENABLE_BROWSER=ON" "-DCEF_ROOT_DIR=../../cef" "-DENABLE_JACK=ON" (lib.cmakeBool "ENABLE_QSV11" stdenv.hostPlatform.isx86_64) @@ -174,7 +185,7 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeBool "ENABLE_ALSA" alsaSupport) (lib.cmakeBool "ENABLE_PULSEAUDIO" pulseaudioSupport) (lib.cmakeBool "ENABLE_PIPEWIRE" pipewireSupport) - (lib.cmakeBool "ENABLE_AJA" false) # TODO: fix linking against libajantv2 + (lib.cmakeBool "ENABLE_AJA" ajaSupport) ]; env.NIX_CFLAGS_COMPILE = toString [ @@ -193,8 +204,13 @@ stdenv.mkDerivation (finalAttrs: { blackmagic-desktop-video ]; in '' - # Remove libcef before patchelf, otherwise it will fail + # Remove cef components before patchelf, otherwise it will fail rm $out/lib/obs-plugins/libcef.so + rm $out/lib/obs-plugins/libEGL.so + rm $out/lib/obs-plugins/libGLESv2.so + rm $out/lib/obs-plugins/libvk_swiftshader.so + rm $out/lib/obs-plugins/libvulkan.so.1 + rm $out/lib/obs-plugins/chrome-sandbox qtWrapperArgs+=( --prefix LD_LIBRARY_PATH : "$out/lib:${lib.makeLibraryPath wrapperLibraries}" @@ -206,8 +222,9 @@ stdenv.mkDerivation (finalAttrs: { addDriverRunpath $out/lib/lib*.so addDriverRunpath $out/lib/obs-plugins/*.so - # Link libcef again after patchelfing other libs + # Link cef components again after patchelfing other libs ln -s ${libcef}/lib/* $out/lib/obs-plugins/ + ln -s ${libcef}/libexec/cef/* $out/lib/obs-plugins/ ''; passthru.updateScript = nix-update-script { }; diff --git a/third_party/nixpkgs/pkgs/by-name/aj/aja-desktop-software/package.nix b/third_party/nixpkgs/pkgs/by-name/aj/aja-desktop-software/package.nix new file mode 100644 index 0000000000..f69404bfe5 --- /dev/null +++ b/third_party/nixpkgs/pkgs/by-name/aj/aja-desktop-software/package.nix @@ -0,0 +1,126 @@ +{ + stdenvNoCC, + lib, + fetchzip, + dpkg, + patchelf, + buildFHSEnv, + writeShellScript, + makeBinaryWrapper, +}: + +let + pname = "aja-desktop-software"; + version = "17.1.3"; + meta = { + description = "Graphical utilities for interacting with AJA desktop video cards"; + homepage = "https://www.aja.com/products/aja-control-room"; + license = lib.licenses.unfree; # https://www.aja.com/software-license-agreement + maintainers = [ lib.maintainers.lukegb ]; + platforms = [ "x86_64-linux" ]; + sourceProvenance = [ + lib.sourceTypes.binaryNativeCode + lib.sourceTypes.binaryFirmware + ]; + }; + + unwrapped = stdenvNoCC.mkDerivation { + pname = "${pname}-unwrapped"; + inherit version; + + src = fetchzip { + url = "https://www.aja.com/assets/support/files/9895/en/AJA-Desktop-Software-Installer_Linux-Ubuntu_v${version}_Release.zip"; + hash = "sha256-TxDcYIhEcpPnpoqpey5vSvUltLT/3xwBfOhAP81Q9+E="; + }; + + unpackCmd = "dpkg -x $curSrc/ajaretail_*.deb source"; + + nativeBuildInputs = [ + dpkg + patchelf + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share + mv usr/share/applications $out/share/applications + mv usr/share/doc $out/share/doc + + mv etc $out/etc + + mv opt $out/opt + + ln -s $out/opt/aja/bin $out/bin + + # For some reason ajanmos doesn't have /opt/aja/lib in its rpath... + patchelf $out/opt/aja/bin/ajanmos --add-rpath $out/opt/aja/lib + + runHook postInstall + ''; + + dontPatchELF = true; + + inherit meta; + }; +in +buildFHSEnv { + inherit pname version; + + targetPkgs = + pkgs: + [ unwrapped ] + ++ (with pkgs; [ + ocl-icd + libGL + udev + libpulseaudio + zstd + glib + fontconfig + freetype + xorg.libxcb + xorg.libX11 + xorg.xcbutilwm + xorg.xcbutilimage + xorg.xcbutilkeysyms + xorg.xcbutilrenderutil + xorg.libSM + xorg.libICE + libxkbcommon + dbus + avahi + ]); + + nativeBuildInputs = [ + makeBinaryWrapper + ]; + + unshareIpc = false; + unsharePid = false; + + runScript = writeShellScript "aja" '' + exec_binary="$1" + shift + export QT_PLUGIN_PATH="${unwrapped}/opt/aja/plugins" + exec "${unwrapped}/opt/aja/bin/$exec_binary" "$@" + ''; + + extraInstallCommands = '' + mkdir -p $out/libexec/aja-desktop + mv $out/bin/${pname} $out/libexec/aja-desktop/${pname} + + for binary in controlpanel controlroom ajanmos systemtest; do + makeWrapper "$out/libexec/aja-desktop/${pname}" "$out/bin/aja-$binary" \ + --add-flags "$binary" + done + ''; + + passthru = { + inherit unwrapped; + }; + + meta = meta // { + mainProgram = "aja-controlpanel"; + }; +} diff --git a/third_party/nixpkgs/pkgs/by-name/li/libajantv2/device-info-list.patch b/third_party/nixpkgs/pkgs/by-name/li/libajantv2/device-info-list.patch new file mode 100644 index 0000000000..c4351ecee0 --- /dev/null +++ b/third_party/nixpkgs/pkgs/by-name/li/libajantv2/device-info-list.patch @@ -0,0 +1,13 @@ +diff --git a/ajantv2/src/ntv2devicescanner.cpp b/ajantv2/src/ntv2devicescanner.cpp +index 448e48d372..6b46f9f69d 100644 +--- a/ajantv2/src/ntv2devicescanner.cpp ++++ b/ajantv2/src/ntv2devicescanner.cpp +@@ -137,7 +137,7 @@ + } + #endif // !defined(NTV2_DEPRECATE_16_3) + +-NTV2DeviceInfoList GetDeviceInfoList (void) ++NTV2DeviceInfoList CNTV2DeviceScanner::GetDeviceInfoList (void) + { + AJAAutoLock tmpLock(&sDevInfoListLock); + return sDevInfoList; diff --git a/third_party/nixpkgs/pkgs/by-name/li/libajantv2/package.nix b/third_party/nixpkgs/pkgs/by-name/li/libajantv2/package.nix index 4b0366d20c..08edfed185 100644 --- a/third_party/nixpkgs/pkgs/by-name/li/libajantv2/package.nix +++ b/third_party/nixpkgs/pkgs/by-name/li/libajantv2/package.nix @@ -5,21 +5,25 @@ cmake, ninja, pkg-config, + mbedtls, + udev, + linuxPackages, }: -# Warning: We are aware that the upstream changed and there are new releases, -# this got initally packaged for obs-studio which appears to fail to build even upstream with the new version. -# https://github.com/NixOS/nixpkgs/pull/296191 / https://github.com/obsproject/obs-studio/pull/10037 stdenv.mkDerivation rec { pname = "libajantv2"; - version = "16.2-bugfix5"; + version = "17.1.0"; src = fetchFromGitHub { owner = "aja-video"; - repo = "ntv2"; - rev = "v${version}"; - sha256 = "sha256-h5PKWMwqTeI5/EaTWkjYojuvDU0FyMpzIjWB98UOJwc="; + repo = "libajantv2"; + rev = "ntv2_${builtins.replaceStrings [ "." ] [ "_" ] version}"; + hash = "sha256-n9j98r1E9E0hv5gA8jCg/eQyqGuyU9JlZYm/zlcTQOo="; }; + patches = [ + ./use-system-mbedtls.patch + ./device-info-list.patch + ]; outputs = [ "out" @@ -31,27 +35,39 @@ stdenv.mkDerivation rec { ninja pkg-config ]; + buildInputs = [ + mbedtls + udev + ]; + + cmakeFlags = [ + (lib.cmakeBool "AJANTV2_BUILD_SHARED" true) + ]; postInstall = '' mkdir -p "$out/lib/pkgconfig" cat >"$out/lib/pkgconfig/libajantv2.pc" < (2024-12-20 18:03:16) +Committer: Luke Granger-Brown (2024-12-20 18:03:25) + + Use system mbedtls, rather than downloading from a random Git branch... + +diff --git a/ajantv2/CMakeLists.txt b/ajantv2/CMakeLists.txt +index ffa572e9c8..74c23e8e4e 100644 +--- a/ajantv2/CMakeLists.txt ++++ b/ajantv2/CMakeLists.txt +@@ -52,49 +52,13 @@ + else() + message(STATUS "NTV2 SDK will load signed 3rd-party plugins") + +- set(MBEDTLS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbedtls-install) +- set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_INSTALL_DIR}/include) +- set(MBEDTLS_LIBRARY_DIR ${MBEDTLS_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}) +- +- if(CMAKE_SYSTEM_NAME STREQUAL "Windows") +- set(MBEDTLS_LIBRARY ${MBEDTLS_LIBRARY_DIR}/mbedtls.lib) +- set(MBEDX509_LIBRARY ${MBEDTLS_LIBRARY_DIR}/mbedx509.lib) +- set(MBEDCRYPTO_LIBRARY ${MBEDTLS_LIBRARY_DIR}/mbedcrypto.lib) +- set(MBEDTLS_EXTRA_CONFIG_FLAGS +- "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON" +- "-DMSVC_STATIC_RUNTIME=ON" +- "-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}") +- elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin)$") +- set(MBEDTLS_LIBRARY ${MBEDTLS_LIBRARY_DIR}/libmbedtls.a) +- set(MBEDX509_LIBRARY ${MBEDTLS_LIBRARY_DIR}/libmbedx509.a) +- set(MBEDCRYPTO_LIBRARY ${MBEDTLS_LIBRARY_DIR}/libmbedcrypto.a) +- set(MBEDTLS_C_FLAGS -fPIC) +- endif() +- +- # BUILD_BYPRODUCTS informing CMake where the .a files are located is required to make Ninja build work +- ExternalProject_Add( +- mbedtls +- GIT_REPOSITORY https://github.com/aja-video/mbedtls.git +- GIT_TAG fix-win-dll-cmake +- CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MBEDTLS_INSTALL_DIR} +- -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} +- -DENABLE_TESTING=OFF +- -DENABLE_PROGRAMS=OFF +- -DCMAKE_C_FLAGS=${MBEDTLS_C_FLAGS} +- -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} +- -DUSE_STATIC_MBEDTLS_LIBRARY=ON +- -DUSE_SHARED_MBEDTLS_LIBRARY=OFF +- ${MBEDTLS_EXTRA_CONFIG_FLAGS} +- BUILD_ALWAYS TRUE +- BUILD_BYPRODUCTS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY} +- ) ++ find_package(PkgConfig REQUIRED) ++ pkg_check_modules(MBEDTLS REQUIRED mbedtls mbedcrypto mbedx509) + + list(APPEND TARGET_INCLUDE_DIRS + ${MBEDTLS_INCLUDE_DIR}) + list(APPEND MBEDTLS_LINK_LIBS +- ${MBEDTLS_LIBRARY} +- ${MBEDCRYPTO_LIBRARY} +- ${MBEDX509_LIBRARY}) ++ ${MBEDTLS_LIBRARIES}) + endif() + + +@@ -668,10 +632,6 @@ + aja_ntv2_log_build_info() + + add_library(${PROJECT_NAME} SHARED ${TARGET_SOURCES}) +- +- if (NOT AJANTV2_DISABLE_PLUGIN_LOAD) +- add_dependencies(${PROJECT_NAME} mbedtls) +- endif() + + target_compile_definitions(${PROJECT_NAME} PUBLIC + ${TARGET_COMPILE_DEFS_DYNAMIC} +@@ -687,10 +647,6 @@ + + add_library(${PROJECT_NAME} STATIC ${TARGET_SOURCES}) + +- if (NOT AJANTV2_DISABLE_PLUGIN_LOAD) +- add_dependencies(${PROJECT_NAME} mbedtls) +- endif() +- + target_compile_definitions(${PROJECT_NAME} PUBLIC + ${TARGET_COMPILE_DEFS_STATIC} + ${AJANTV2_TARGET_COMPILE_DEFS}) diff --git a/third_party/nixpkgs/pkgs/development/libraries/libcef/default.nix b/third_party/nixpkgs/pkgs/development/libraries/libcef/default.nix index 9595efc1c1..e33072ef5f 100644 --- a/third_party/nixpkgs/pkgs/development/libraries/libcef/default.nix +++ b/third_party/nixpkgs/pkgs/development/libraries/libcef/default.nix @@ -93,15 +93,20 @@ stdenv.mkDerivation rec { dontPatchELF = true; installPhase = '' - mkdir -p $out/lib/ $out/share/cef/ + mkdir -p $out/lib/ $out/share/cef/ $out/libexec/cef/ cp libcef_dll_wrapper/libcef_dll_wrapper.a $out/lib/ cp ../Release/libcef.so $out/lib/ cp ../Release/libEGL.so $out/lib/ cp ../Release/libGLESv2.so $out/lib/ + cp ../Release/libvk_swiftshader.so $out/lib/ + cp ../Release/libvulkan.so.1 $out/lib/ + cp ../Release/chrome-sandbox $out/libexec/cef/ patchelf --set-rpath "${rpath}" $out/lib/libcef.so patchelf --set-rpath "${gl_rpath}" $out/lib/libEGL.so patchelf --set-rpath "${gl_rpath}" $out/lib/libGLESv2.so - cp ../Release/*.bin $out/share/cef/ + patchelf --set-rpath "${gl_rpath}" $out/lib/libvk_swiftshader.so + patchelf --set-rpath "${gl_rpath}" $out/lib/libvulkan.so.1 + cp ../Release/*.bin ../Release/*.json $out/share/cef/ cp -r ../Resources/* $out/share/cef/ cp -r ../include $out/ ''; diff --git a/third_party/nixpkgs/pkgs/os-specific/linux/ajantv2/default.nix b/third_party/nixpkgs/pkgs/os-specific/linux/ajantv2/default.nix new file mode 100644 index 0000000000..b3c38b7da9 --- /dev/null +++ b/third_party/nixpkgs/pkgs/os-specific/linux/ajantv2/default.nix @@ -0,0 +1,41 @@ +{ + lib, + stdenv, + fetchFromGitHub, + kernel, + libajantv2, +}: +stdenv.mkDerivation { + name = "ajantv2-module-${libajantv2.version}-${kernel.version}"; + + inherit (libajantv2) src; + sourceRoot = "source/driver/linux"; + + hardeningDisable = [ "pic" ]; + + nativeBuildInputs = kernel.moduleBuildDependencies; + + preBuild = '' + chmod -R +w ../../ + ''; + + enableParallelBuilding = true; + + buildFlags = [ + "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + ]; + + installPhase = '' + install -D ajantv2.ko $out/lib/modules/${kernel.modDirVersion}/misc/ajantv2.ko + install -D ajardma.ko $out/lib/modules/${kernel.modDirVersion}/misc/ajardma.ko + ''; + + meta = { + inherit (libajantv2.meta) license homepage maintainers; + platforms = [ + "x86_64-linux" + "aarch64-linux" + ]; + description = "AJA video driver"; + }; +} diff --git a/third_party/nixpkgs/pkgs/top-level/linux-kernels.nix b/third_party/nixpkgs/pkgs/top-level/linux-kernels.nix index dede77df2b..e49d07d88e 100644 --- a/third_party/nixpkgs/pkgs/top-level/linux-kernels.nix +++ b/third_party/nixpkgs/pkgs/top-level/linux-kernels.nix @@ -321,6 +321,8 @@ in { acpi_call = callPackage ../os-specific/linux/acpi-call {}; + ajantv2 = callPackage ../os-specific/linux/ajantv2 { }; + akvcam = callPackage ../os-specific/linux/akvcam { }; amneziawg = callPackage ../os-specific/linux/amneziawg { };