xorg.xorgserver: Fix Xquartz stub on macOS

Xquartz has been broken since #40574 because the Xquartz binary
couldn't find the corresponding XQuartz.app. This commit restores an
earlier patch to use an environment variable to find XQuartz.app, and
additionally embeds the path to the XQuartz.app's Nix store location
as a default.

+70
+61
pkgs/servers/x11/xorg/darwin/stub.patch
··· 1 + When the X / Xquartz server initializes, it starts the XQuartz.app and 2 + hands-off the display FD. To start the XQuartz.app, Xquartz normally uses some 3 + system calls to get the path of the application by app bundle id, and then 4 + executes the Contents/MacOS/X11 script contained inside, which in turn executes 5 + Contents/MacOS/X11.bin (the actual app). 6 + 7 + This patch replaces that discovery technique with a simple call to 8 + `getenv' and a hardcoded default. In order to make Xquartz work if the 9 + app is moved, we'll need another wrapper that sets the `XQUARTZ_X11' 10 + environment variable to point to the `X11' script. 11 + 12 + diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c 13 + index 83252e805..f1974215b 100644 14 + --- a/hw/xquartz/mach-startup/stub.c 15 + +++ b/hw/xquartz/mach-startup/stub.c 16 + @@ -52,7 +52,6 @@ 17 + 18 + #include "launchd_fd.h" 19 + 20 + -static CFURLRef x11appURL; 21 + static FSRef x11_appRef; 22 + static pid_t x11app_pid = 0; 23 + aslclient aslc; 24 + @@ -60,29 +59,21 @@ aslclient aslc; 25 + static void 26 + set_x11_path(void) 27 + { 28 + - OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), 29 + - nil, &x11_appRef, &x11appURL); 30 + + unsigned char *xquartzApp = getenv("XQUARTZ_APP"); 31 + + if (!xquartzApp) { 32 + + xquartzApp = "@XQUARTZ_APP@"; 33 + + } 34 + + 35 + + OSStatus osstatus = FSPathMakeRef(xquartzApp, &x11_appRef, NULL); 36 + 37 + switch (osstatus) { 38 + case noErr: 39 + - if (x11appURL == NULL) { 40 + - asl_log(aslc, NULL, ASL_LEVEL_ERR, 41 + - "Xquartz: Invalid response from LSFindApplicationForInfo(%s)", 42 + - kX11AppBundleId); 43 + - exit(1); 44 + - } 45 + break; 46 + 47 + - case kLSApplicationNotFoundErr: 48 + - asl_log(aslc, NULL, ASL_LEVEL_ERR, 49 + - "Xquartz: Unable to find application for %s", 50 + - kX11AppBundleId); 51 + - exit(10); 52 + - 53 + default: 54 + asl_log(aslc, NULL, ASL_LEVEL_ERR, 55 + - "Xquartz: Unable to find application for %s, error code = %d", 56 + - kX11AppBundleId, (int)osstatus); 57 + + "Xquartz: Unable to find FSRef for %s, error code = %d", 58 + + xquartzApp, (int)osstatus); 59 + exit(11); 60 + } 61 + }
+9
pkgs/servers/x11/xorg/overrides.nix
··· 763 763 sha256 = "0zm9g0g1jvy79sgkvy0rjm6ywrdba2xjd1nsnjbxjccckbr6i396"; 764 764 name = "revert-fb-changes-2.patch"; 765 765 }) 766 + ./darwin/stub.patch 766 767 ]; 768 + 769 + postPatch = attrs.postPatch + '' 770 + substituteInPlace hw/xquartz/mach-startup/stub.c \ 771 + --subst-var-by XQUARTZ_APP "$out/Applications/XQuartz.app" 772 + ''; 767 773 768 774 configureFlags = [ 769 775 # note: --enable-xquartz is auto ··· 774 780 "--with-apple-applications-dir=\${out}/Applications" 775 781 "--with-bundle-id-prefix=org.nixos.xquartz" 776 782 "--with-sha1=CommonCrypto" 783 + "--with-xkb-bin-directory=${xorg.xkbcomp}/bin" 784 + "--with-xkb-path=${xorg.xkeyboardconfig}/share/X11/xkb" 785 + "--with-xkb-output=$out/share/X11/xkb/compiled" 777 786 "--without-dtrace" # requires Command Line Tools for Xcode 778 787 ]; 779 788 preConfigure = ''