From 3987ea9a9d4464869ac6b8e8519a386190b6b68d Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Thu, 6 Feb 2020 14:15:35 +0100 Subject: [PATCH 1/2] mpv: add flag for swift on darwin While we currently don't have a pure swift build on macOS it's possible to build mpv using the swift compiler from CLT. eg. self: super: let CommandLineTools = "/Library/Developer/CommandLineTools"; in { swift = super.stdenv.mkDerivation { name = "swift-CommandLineTools-0.0.0"; phases = [ "installPhase" "fixupPhase" ]; propagatedBuildInputs = [ self.darwin.DarwinTools ]; installPhase = '' mkdir -p $out/bin $out/lib ln -s ${CommandLineTools}/usr/bin/swift $out/bin ln -s ${CommandLineTools}/usr/lib/swift $out/lib ln -s ${CommandLineTools}/SDKs $out ''; setupHook = builtins.toFile "hook" '' addCommandLineTools() { echo >&2 echo "WARNING: this is impure and unreliable, make sure the CommandLineTools are installed!" >&2 echo " $ xcode-select --install" >&2 echo >&2 [ -d ${CommandLineTools} ] export NIX_LDFLAGS+=" -L@out@/lib/swift/macosx" export SWIFT=swift export SWIFT_LIB_DYNAMIC=@out@/lib/swift/macosx export MACOS_SDK_VERSION=$(sw_vers -productVersion | awk -F. '{print $1 "." $2}') export MACOS_SDK=@out@/SDKs/MacOSX$MACOS_SDK_VERSION.sdk } prePhases+=" addCommandLineTools" ''; __impureHostDeps = [ CommandLineTools ]; }; mpv = super.mpv.override { swiftSupport = true; }; } --- pkgs/applications/video/mpv/default.nix | 12 +++++++----- pkgs/os-specific/darwin/apple-sdk/frameworks.nix | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/video/mpv/default.nix b/pkgs/applications/video/mpv/default.nix index f7ac5ef58cdf..052e190a3e16 100644 --- a/pkgs/applications/video/mpv/default.nix +++ b/pkgs/applications/video/mpv/default.nix @@ -38,11 +38,12 @@ , libpngSupport ? true, libpng ? null , pulseSupport ? config.pulseaudio or stdenv.isLinux, libpulseaudio ? null , rubberbandSupport ? stdenv.isLinux, rubberband ? null -, screenSaverSupport ? true, libXScrnSaver ? null , sambaSupport ? stdenv.isLinux, samba ? null +, screenSaverSupport ? true, libXScrnSaver ? null , sdl2Support ? true, SDL2 ? null , sndioSupport ? true, sndio ? null , speexSupport ? true, speex ? null +, swiftSupport ? false, swift ? null , theoraSupport ? true, libtheora ? null , vaapiSupport ? stdenv.isLinux, libva ? null , vdpauSupport ? true, libvdpau ? null @@ -119,7 +120,6 @@ in stdenv.mkDerivation rec { "--disable-libmpv-static" "--disable-static-build" "--disable-build-date" # Purity - "--disable-macos-cocoa-cb" # Disable whilst Swift isn't supported (enableFeature archiveSupport "libarchive") (enableFeature cddaSupport "cdda") (enableFeature dvdnavSupport "dvdnav") @@ -130,11 +130,13 @@ in stdenv.mkDerivation rec { (enableFeature vaapiSupport "vaapi") (enableFeature waylandSupport "wayland") (enableFeature stdenv.isLinux "dvbin") - ]; + ] # Disable whilst Swift isn't supported + ++ stdenv.lib.optional (!swiftSupport) "--disable-macos-cocoa-cb"; nativeBuildInputs = [ addOpenGLRunpath docutils makeWrapper perl pkgconfig python3 wafHook which - ]; + ] + ++ optional swiftSupport swift; buildInputs = [ ffmpeg_4 freetype libass libpthreadstubs @@ -172,7 +174,7 @@ in stdenv.mkDerivation rec { ++ optionals x11Support [ libX11 libXext libGLU libGL libXxf86vm libXrandr ] ++ optionals vulkanSupport [ libplacebo shaderc vulkan-headers vulkan-loader ] ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ - CoreFoundation Cocoa CoreAudio + CoreFoundation Cocoa CoreAudio MediaPlayer ]); enableParallelBuilding = true; diff --git a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix index 09e0e4e48ecd..02e2421f3472 100644 --- a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix @@ -75,6 +75,7 @@ with frameworks; with libs; { LocalAuthentication = []; MapKit = []; MediaAccessibility = [ CoreGraphics CoreText QuartzCore ]; + MediaPlayer = []; MediaToolbox = [ AudioToolbox AudioUnit CoreMedia ]; Metal = []; MetalKit = [ ModelIO Metal ]; From 408f36923dd1efdc00dde6ed917945df6b625cbb Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Fri, 7 Feb 2020 22:09:23 +0100 Subject: [PATCH 2/2] mpv: call with frameworks Referencing darwin.* directly makes overriding dependencies very awkward. --- pkgs/applications/video/mpv/default.nix | 7 +++---- pkgs/top-level/all-packages.nix | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/video/mpv/default.nix b/pkgs/applications/video/mpv/default.nix index 052e190a3e16..f1713fe29d4b 100644 --- a/pkgs/applications/video/mpv/default.nix +++ b/pkgs/applications/video/mpv/default.nix @@ -1,7 +1,8 @@ { config, stdenv, fetchurl, fetchFromGitHub, makeWrapper , addOpenGLRunpath, docutils, perl, pkgconfig, python3, wafHook, which , ffmpeg_4, freefont_ttf, freetype, libass, libpthreadstubs, mujs -, nv-codec-headers, lua, libuchardet, libiconv ? null, darwin +, nv-codec-headers, lua, libuchardet, libiconv ? null +, CoreFoundation, Cocoa, CoreAudio, MediaPlayer , waylandSupport ? stdenv.isLinux , wayland ? null @@ -173,9 +174,7 @@ in stdenv.mkDerivation rec { ++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ] ++ optionals x11Support [ libX11 libXext libGLU libGL libXxf86vm libXrandr ] ++ optionals vulkanSupport [ libplacebo shaderc vulkan-headers vulkan-loader ] - ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ - CoreFoundation Cocoa CoreAudio MediaPlayer - ]); + ++ optionals stdenv.isDarwin [ CoreFoundation Cocoa CoreAudio MediaPlayer ]; enableParallelBuilding = true; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e351a5f90642..3916e71751c6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -20379,6 +20379,7 @@ in mpv = callPackage ../applications/video/mpv { inherit lua; + inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa CoreAudio MediaPlayer; }; mpv-with-scripts = callPackage ../applications/video/mpv/wrapper.nix { };