From 3871f8be8d6de48d5f094fbe90a09e42cc0b289c Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Thu, 7 Jul 2022 18:41:47 +0200 Subject: [PATCH] pulseaudioFull: fix wrapGApp wrapping Since https://github.com/NixOS/nixpkgs/commit/7a2605e0f3dc99e02cd577634f792f7a4d229378 the pulseaudio build recipe incorporates the `wrapGAppsHook` wrapper setup-hook if `advancedBluetoothCodecs` are enabled. This wrapper setup-hook -- like most wrappers -- wraps binaries in `$out/bin` by first renaming them, then placing a wrapper script where the original binary was. Unfortunatelly, pulseaudio doesn't like its binary moved around after installation: It records the binaries path during installation time https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/e5ad31e873eed62bc580a86a61177047f9e8c491/meson.build#L154 then checks the path in `/proc/self/exe` and complains > Jun 16 19:06:48 nixosb pulseaudio[2219]: W: [.pulseaudio-wra] main.c: /proc/self/exe does not point to /nix/store/bqfyzxwpxa2ydmyvh3j32xrm4chxbj22-pulseaudio-15.0/bin/pulseaudio, cannot self execute. Are you playing games? if they don't match https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/e5ad31e873eed62bc580a86a61177047f9e8c491/src/daemon/main.c#L577 Somehow, this also results in a real bug: `pacmd` fails to connect to the pulseaudio server, see https://github.com/NixOS/nixpkgs/issues/177915 To fix this issue, the commit at hand changes the installation directory for binaries to `$out/.bin-unwrapped`. After the installation, `$out/bin` is created by hand and populated with symlinks to files in `$out/.bin-unwrapped`. `wrapGAppsHook` doesn't know or care about the `.bin-unwrapped` directory; it just sees all the symlinks in `bin`, renames them and places wrapper scripts beside them. Effectively, this leaves the original binary in `.bin-unwrapped` unchanged! So pulseaudio will find itself still in its oritinal place, and "users" of the package can call pulseaudio via the wrapper script in `bin` as usual. --- pkgs/servers/pulseaudio/default.nix | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkgs/servers/pulseaudio/default.nix b/pkgs/servers/pulseaudio/default.nix index ee2c0e0bd1c5..6dc158600fd1 100644 --- a/pkgs/servers/pulseaudio/default.nix +++ b/pkgs/servers/pulseaudio/default.nix @@ -116,6 +116,11 @@ stdenv.mkDerivation rec { "-Dsysconfdir=/etc" "-Dsysconfdir_install=${placeholder "out"}/etc" "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d" + + # pulseaudio complains if its binary is moved after installation; + # this is needed so that wrapGApp can operate *without* + # renaming the unwrapped binaries (see below) + "--bindir=${placeholder "out"}/.bin-unwrapped" ] ++ lib.optional (stdenv.isLinux && useSystemd) "-Dsystemduserunitdir=${placeholder "out"}/lib/systemd/user" ++ lib.optionals stdenv.isDarwin [ @@ -133,11 +138,11 @@ stdenv.mkDerivation rec { postInstall = lib.optionalString libOnly '' find $out/share -maxdepth 1 -mindepth 1 ! -name "vala" -prune -exec rm -r {} \; find $out/share/vala -maxdepth 1 -mindepth 1 ! -name "vapi" -prune -exec rm -r {} \; - rm -r $out/{bin,etc,lib/pulse-*} + rm -r $out/{.bin-unwrapped,etc,lib/pulse-*} '' + '' moveToOutput lib/cmake "$dev" - rm -f $out/bin/qpaeq # this is packaged by the "qpaeq" package now, because of missing deps + rm -f $out/.bin-unwrapped/qpaeq # this is packaged by the "qpaeq" package now, because of missing deps ''; preFixup = lib.optionalString (stdenv.isLinux && (stdenv.hostPlatform == stdenv.buildPlatform)) '' @@ -151,6 +156,15 @@ stdenv.mkDerivation rec { ln -s "''$file" "''${file%.dylib}.so" ln -s "''$file" "$out/lib/pulseaudio/''$(basename ''$file .dylib).so" done + '' + # put symlinks to binaries in `$prefix/bin`; + # then wrapGApp will *rename these symlinks* instead of + # the original binaries in `$prefix/.bin-unwrapped` (see above); + # when pulseaudio is looking for its own binary (it does!), + # it will be happy to find it in its original installation location + + lib.optionalString (!libOnly) '' + mkdir -p $out/bin + ln -st $out/bin $out/.bin-unwrapped/* ''; passthru = {