Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpv: clean‐ups and Darwin improvements #350674

Merged
merged 21 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 32 additions & 104 deletions pkgs/applications/video/mpv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
buildPackages,
callPackage,
config,
darwin,
docutils,
fetchFromGitHub,
ffmpeg,
freefont_ttf,
freetype,
lcms2,
libGL,
libGLU,
libX11,
libXScrnSaver,
libXext,
libXinerama,
libXpresent,
libXrandr,
libXv,
libXxf86vm,
libarchive,
libass,
libbluray,
Expand All @@ -33,19 +28,17 @@
libcdio-paranoia,
libdrm,
libdvdnav,
libiconv,
libjack2,
libplacebo,
libpng,
libpthreadstubs,
libpulseaudio,
libsixel,
libtheora,
libuchardet,
libva,
libvdpau,
libxkbcommon,
lua,
makeWrapper,
mesa,
meson,
mujs,
Expand All @@ -58,7 +51,6 @@
python3,
rubberband,
shaderc, # instead of spirv-cross
speex,
stdenv,
swift,
testers,
Expand All @@ -68,7 +60,6 @@
wayland,
wayland-protocols,
wayland-scanner,
xcbuild,
zimg,

# Boolean
Expand All @@ -81,59 +72,28 @@
cmsSupport ? true,
drmSupport ? stdenv.hostPlatform.isLinux,
dvbinSupport ? stdenv.hostPlatform.isLinux,
dvdnavSupport ? stdenv.hostPlatform.isLinux,
dvdnavSupport ? true,
jackaudioSupport ? false,
javascriptSupport ? true,
libpngSupport ? true,
openalSupport ? true,
pipewireSupport ? stdenv.hostPlatform.isLinux,
pulseSupport ? config.pulseaudio or stdenv.hostPlatform.isLinux,
pipewireSupport ? !stdenv.hostPlatform.isDarwin,
pulseSupport ? config.pulseaudio or (!stdenv.hostPlatform.isDarwin),
fpletz marked this conversation as resolved.
Show resolved Hide resolved
rubberbandSupport ? true,
screenSaverSupport ? true,
sdl2Support ? !stdenv.hostPlatform.isDarwin,
sdl2Support ? false,
sixelSupport ? false,
speexSupport ? true,
swiftSupport ? stdenv.hostPlatform.isDarwin,
theoraSupport ? true,
vaapiSupport ? x11Support || waylandSupport,
vaapiSupport ? !stdenv.hostPlatform.isDarwin && (x11Support || waylandSupport),
vapoursynthSupport ? false,
vdpauSupport ? true,
vulkanSupport ? stdenv.hostPlatform.isLinux,
waylandSupport ? stdenv.hostPlatform.isLinux,
x11Support ? stdenv.hostPlatform.isLinux,
xineramaSupport ? stdenv.hostPlatform.isLinux,
xvSupport ? stdenv.hostPlatform.isLinux,
vulkanSupport ? true,
waylandSupport ? !stdenv.hostPlatform.isDarwin,
x11Support ? !stdenv.hostPlatform.isDarwin,
zimgSupport ? true,
}:

let
inherit (darwin.apple_sdk_11_0.frameworks)
AVFoundation
Accelerate
Cocoa
CoreAudio
CoreFoundation
CoreMedia
MediaPlayer
VideoToolbox
;
luaEnv = lua.withPackages (ps: with ps; [ luasocket ]);

overrideSDK =
platform: version:
platform // lib.optionalAttrs (platform ? darwinMinVersion) { darwinMinVersion = version; };

stdenv' =
if swiftSupport && stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64 then
stdenv.override (old: {
buildPlatform = overrideSDK old.buildPlatform "11.0";
hostPlatform = overrideSDK old.hostPlatform "11.0";
targetPlatform = overrideSDK old.targetPlatform "11.0";
})
else
stdenv;
in
stdenv'.mkDerivation (finalAttrs: {
stdenv.mkDerivation (finalAttrs: {
pname = "mpv";
version = "0.39.0";

Expand All @@ -151,18 +111,13 @@ stdenv'.mkDerivation (finalAttrs: {
hash = "sha256-BOGh+QBTO7hrHohh+RqjSF8eHQH8jVBPjG/k4eyFaaM=";
};

patches = [
# Fix build with Darwin SDK 11
./0001-fix-darwin-build.patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this file removed from Nixpkgs repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to, but it’s possible it got lost in rebasing. Will open a PR soon if nobody beats me to it (currently racing against time for the 24.11 freeze).

];

postPatch = lib.concatStringsSep "\n" [
# Don't reference compile time dependencies or create a build outputs cycle
# between out and dev
''
substituteInPlace meson.build \
--replace-fail "conf_data.set_quoted('CONFIGURATION', configuration)" \
"conf_data.set_quoted('CONFIGURATION', '<ommited>')"
"conf_data.set_quoted('CONFIGURATION', '<omitted>')"
''
# A trick to patchShebang everything except mpv_identify.sh
''
Expand All @@ -174,30 +129,16 @@ stdenv'.mkDerivation (finalAttrs: {
''
];

# Ensure we reference 'lib' (not 'out') of Swift.
preConfigure = lib.optionalString swiftSupport ''
export SWIFT_LIB_DYNAMIC="${lib.getLib swift.swift}/lib/swift/macosx"
'';

mesonFlags =
[
(lib.mesonOption "default_library" "shared")
(lib.mesonBool "libmpv" true)
(lib.mesonEnable "libarchive" archiveSupport)
(lib.mesonEnable "manpage-build" true)
(lib.mesonEnable "cdda" cddaSupport)
(lib.mesonEnable "dvbin" dvbinSupport)
(lib.mesonEnable "dvdnav" dvdnavSupport)
(lib.mesonEnable "openal" openalSupport)
(lib.mesonEnable "sdl2" sdl2Support)
# Disable whilst Swift isn't supported
(lib.mesonEnable "swift-build" swiftSupport)
(lib.mesonEnable "macos-cocoa-cb" swiftSupport)
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Toggle explicitly because it fails on darwin
(lib.mesonEnable "videotoolbox-pl" vulkanSupport)
];
mesonFlags = [
(lib.mesonOption "default_library" "shared")
(lib.mesonBool "libmpv" true)
(lib.mesonEnable "manpage-build" true)
(lib.mesonEnable "cdda" cddaSupport)
(lib.mesonEnable "dvbin" dvbinSupport)
(lib.mesonEnable "dvdnav" dvdnavSupport)
(lib.mesonEnable "openal" openalSupport)
(lib.mesonEnable "sdl2" sdl2Support)
];

mesonAutoFeatures = "auto";

Expand All @@ -211,9 +152,9 @@ stdenv'.mkDerivation (finalAttrs: {
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
buildPackages.darwin.sigtool
xcbuild.xcrun
swift
makeWrapper
]
++ lib.optionals swiftSupport [ swift ]
++ lib.optionals waylandSupport [ wayland-scanner ];

buildInputs =
Expand Down Expand Up @@ -248,16 +189,12 @@ stdenv'.mkDerivation (finalAttrs: {
]
++ lib.optionals jackaudioSupport [ libjack2 ]
++ lib.optionals javascriptSupport [ mujs ]
++ lib.optionals libpngSupport [ libpng ]
++ lib.optionals openalSupport [ openalSoft ]
++ lib.optionals pipewireSupport [ pipewire ]
++ lib.optionals pulseSupport [ libpulseaudio ]
++ lib.optionals rubberbandSupport [ rubberband ]
++ lib.optionals screenSaverSupport [ libXScrnSaver ]
++ lib.optionals sdl2Support [ SDL2 ]
++ lib.optionals sixelSupport [ libsixel ]
++ lib.optionals speexSupport [ speex ]
++ lib.optionals theoraSupport [ libtheora ]
++ lib.optionals vaapiSupport [ libva ]
++ lib.optionals vapoursynthSupport [ vapoursynth ]
++ lib.optionals vdpauSupport [ libvdpau ]
Expand All @@ -274,29 +211,13 @@ stdenv'.mkDerivation (finalAttrs: {
++ lib.optionals x11Support [
libX11
libXext
libGLU
libGL
libXxf86vm
libXrandr
libXpresent
libXScrnSaver
]
++ lib.optionals xineramaSupport [ libXinerama ]
++ lib.optionals xvSupport [ libXv ]
++ lib.optionals zimgSupport [ zimg ]
++ lib.optionals stdenv.hostPlatform.isLinux [ nv-codec-headers-11 ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
++ lib.optionals stdenv.hostPlatform.isDarwin [
Accelerate
CoreFoundation
Cocoa
CoreAudio
MediaPlayer
VideoToolbox
]
++ lib.optionals (stdenv.hostPlatform.isDarwin && swiftSupport) [
AVFoundation
CoreMedia
];
++ lib.optionals stdenv.hostPlatform.isLinux [ nv-codec-headers-11 ];

postBuild = lib.optionalString stdenv.hostPlatform.isDarwin ''
pushd .. # Must be run from the source dir because it uses relative paths
Expand Down Expand Up @@ -325,6 +246,13 @@ stdenv'.mkDerivation (finalAttrs: {
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
cp -r mpv.app $out/Applications
# On macOS, many things won’t work properly unless `mpv(1)` is
# executed from the app bundle, such as spatial audio with
# `--ao=avfoundation`. This wrapper ensures that those features
# work reliably and also avoids shipping two copies of the entire
# `mpv` executable.
makeWrapper $out/Applications/mpv.app/Contents/MacOS/mpv $out/bin/mpv
'';

# Set RUNPATH so that libcuda in /run/opengl-driver(-32)/lib can be found.
Expand Down
4 changes: 4 additions & 0 deletions pkgs/by-name/mo/moltenvk/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ stdenv.mkDerivation (finalAttrs: {
"-isystem ${lib.getDev libcxx}/include/c++/v1"
"-I${lib.getDev spirv-cross}/include/spirv_cross"
"-I${lib.getDev spirv-headers}/include/spirv/unified1"

# MoltenVK prints a lot of verbose output to the console out of
# the box; we adjust this to match Homebrew’s default log level.
"-DMVK_CONFIG_LOG_LEVEL=MVK_CONFIG_LOG_LEVEL_NONE"
]
++ lib.optional enablePrivateAPIUsage "-DMVK_USE_METAL_PRIVATE_API=1"
);
Expand Down
3 changes: 1 addition & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31181,9 +31181,8 @@ with pkgs;
libdvdnav = libdvdnav_4_2_1;
} // (config.mplayer or {}));

mpv-unwrapped = darwin.apple_sdk_11_0.callPackage ../applications/video/mpv {
mpv-unwrapped = callPackage ../applications/video/mpv {
stdenv = if stdenv.hostPlatform.isDarwin then swiftPackages.stdenv else stdenv;
inherit lua;
};

# Wrap avoiding rebuild
Expand Down