From f7416d72f65b563075fc5fdd213e20cf1fef0cb0 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 25 Apr 2023 02:39:03 -0400 Subject: [PATCH 1/6] 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. --- pkgs/servers/x11/xorg/darwin/stub.patch | 61 +++++++++++++++++++++++++ pkgs/servers/x11/xorg/overrides.nix | 9 ++++ 2 files changed, 70 insertions(+) create mode 100644 pkgs/servers/x11/xorg/darwin/stub.patch diff --git a/pkgs/servers/x11/xorg/darwin/stub.patch b/pkgs/servers/x11/xorg/darwin/stub.patch new file mode 100644 index 000000000000..0005c3568dff --- /dev/null +++ b/pkgs/servers/x11/xorg/darwin/stub.patch @@ -0,0 +1,61 @@ +When the X / Xquartz server initializes, it starts the XQuartz.app and +hands-off the display FD. To start the XQuartz.app, Xquartz normally uses some +system calls to get the path of the application by app bundle id, and then +executes the Contents/MacOS/X11 script contained inside, which in turn executes +Contents/MacOS/X11.bin (the actual app). + +This patch replaces that discovery technique with a simple call to +`getenv' and a hardcoded default. In order to make Xquartz work if the +app is moved, we'll need another wrapper that sets the `XQUARTZ_X11' +environment variable to point to the `X11' script. + +diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c +index 83252e805..f1974215b 100644 +--- a/hw/xquartz/mach-startup/stub.c ++++ b/hw/xquartz/mach-startup/stub.c +@@ -52,7 +52,6 @@ + + #include "launchd_fd.h" + +-static CFURLRef x11appURL; + static FSRef x11_appRef; + static pid_t x11app_pid = 0; + aslclient aslc; +@@ -60,29 +59,21 @@ aslclient aslc; + static void + set_x11_path(void) + { +- OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), +- nil, &x11_appRef, &x11appURL); ++ unsigned char *xquartzApp = getenv("XQUARTZ_APP"); ++ if (!xquartzApp) { ++ xquartzApp = "@XQUARTZ_APP@"; ++ } ++ ++ OSStatus osstatus = FSPathMakeRef(xquartzApp, &x11_appRef, NULL); + + switch (osstatus) { + case noErr: +- if (x11appURL == NULL) { +- asl_log(aslc, NULL, ASL_LEVEL_ERR, +- "Xquartz: Invalid response from LSFindApplicationForInfo(%s)", +- kX11AppBundleId); +- exit(1); +- } + break; + +- case kLSApplicationNotFoundErr: +- asl_log(aslc, NULL, ASL_LEVEL_ERR, +- "Xquartz: Unable to find application for %s", +- kX11AppBundleId); +- exit(10); +- + default: + asl_log(aslc, NULL, ASL_LEVEL_ERR, +- "Xquartz: Unable to find application for %s, error code = %d", +- kX11AppBundleId, (int)osstatus); ++ "Xquartz: Unable to find FSRef for %s, error code = %d", ++ xquartzApp, (int)osstatus); + exit(11); + } + } diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index fe572da71565..ad3d3116a04a 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -763,8 +763,14 @@ self: super: sha256 = "0zm9g0g1jvy79sgkvy0rjm6ywrdba2xjd1nsnjbxjccckbr6i396"; name = "revert-fb-changes-2.patch"; }) + ./darwin/stub.patch ]; + postPatch = attrs.postPatch + '' + substituteInPlace hw/xquartz/mach-startup/stub.c \ + --subst-var-by XQUARTZ_APP "$out/Applications/XQuartz.app" + ''; + configureFlags = [ # note: --enable-xquartz is auto "CPPFLAGS=-I${./darwin/dri}" @@ -774,6 +780,9 @@ self: super: "--with-apple-applications-dir=\${out}/Applications" "--with-bundle-id-prefix=org.nixos.xquartz" "--with-sha1=CommonCrypto" + "--with-xkb-bin-directory=${xorg.xkbcomp}/bin" + "--with-xkb-path=${xorg.xkeyboardconfig}/share/X11/xkb" + "--with-xkb-output=$out/share/X11/xkb/compiled" "--without-dtrace" # requires Command Line Tools for Xcode ]; preConfigure = '' From d2cd23b9deec83a8c65abf8f2d2ace600922479e Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 25 Apr 2023 03:16:19 -0400 Subject: [PATCH 2/6] xorg.xorgserver: Restore XQuartz.app's usage of environment variables. XQuartz.app needs to be able to find the `startx' from the `xinit' package, but it defaults to assuming it is in the same directory as the Xquartz binary, which it will never be. This restores a patch that uses environment variables to locate `startx', which is what the `xquartz' package is expecting to use. --- .../servers/x11/xorg/darwin/bundle_main.patch | 84 +++++++++++++++++++ pkgs/servers/x11/xorg/overrides.nix | 1 + 2 files changed, 85 insertions(+) create mode 100644 pkgs/servers/x11/xorg/darwin/bundle_main.patch diff --git a/pkgs/servers/x11/xorg/darwin/bundle_main.patch b/pkgs/servers/x11/xorg/darwin/bundle_main.patch new file mode 100644 index 000000000000..5d4c97d6684c --- /dev/null +++ b/pkgs/servers/x11/xorg/darwin/bundle_main.patch @@ -0,0 +1,84 @@ +This patch makes it possible (and necessary) to specify the default +shell, xterm client, and startx script from environment variables. These +defaults are used when launching the XQuartz.app, which in turn needs to know +how to start the X server. `startx' comes from the `xinit' package, +which also has a dependency on `xorg-server', so we can't hardcode +sane defaults. If the environment variables are specified, they +override any value in the preferences settings. + +When developing an installable package for XQuartz/XQuartz.app, we'll +need to set an `LSEnvironment' entry in the plist for the XQuartz.app. +(See stub.patch for more details.). + +diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c +index de82e2280..da58a5d44 100644 +--- a/hw/xquartz/mach-startup/bundle-main.c ++++ b/hw/xquartz/mach-startup/bundle-main.c +@@ -76,8 +76,6 @@ extern int noPanoramiXExtension; + extern Bool noCompositeExtension; + #endif + +-#define DEFAULT_CLIENT X11BINDIR "/xterm" +-#define DEFAULT_STARTX X11BINDIR "/startx -- " X11BINDIR "/Xquartz" + #define DEFAULT_SHELL "/bin/sh" + + #define _STRINGIZE(s) #s +@@ -108,7 +106,7 @@ server_main(int argc, char **argv, char **envp); + static int + execute(const char *command); + static char * +-command_from_prefs(const char *key, const char *default_value); ++command_from_prefs(const char *key, const char *env_name, const char *default_value); + + static char *pref_app_to_run; + static char *pref_login_shell; +@@ -669,14 +667,19 @@ main(int argc, char **argv, char **envp) + pid_t child1, child2; + int status; + +- pref_app_to_run = command_from_prefs("app_to_run", DEFAULT_CLIENT); ++ pref_app_to_run = command_from_prefs("app_to_run", ++ "XQUARTZ_DEFAULT_CLIENT", ++ NULL); + assert(pref_app_to_run); + +- pref_login_shell = command_from_prefs("login_shell", DEFAULT_SHELL); ++ pref_login_shell = command_from_prefs("login_shell", ++ "XQUARTZ_DEFAULT_SHELL", ++ DEFAULT_SHELL); + assert(pref_login_shell); + + pref_startx_script = command_from_prefs("startx_script", +- DEFAULT_STARTX); ++ "XQUARTZ_DEFAULT_STARTX", ++ NULL); + assert(pref_startx_script); + + /* Do the fork-twice trick to avoid having to reap zombies */ +@@ -753,7 +756,7 @@ execute(const char *command) + } + + static char * +-command_from_prefs(const char *key, const char *default_value) ++command_from_prefs(const char *key, const char *env_name, const char *default_value) + { + char *command = NULL; + +@@ -763,6 +766,17 @@ command_from_prefs(const char *key, const char *default_value) + if (!key) + return NULL; + ++ if (env_name != NULL) { ++ command = getenv(env_name); ++ if (command != NULL) { ++ return strdup(command); ++ } ++ } ++ ++ if (!default_value) { ++ return NULL; ++ } ++ + cfKey = CFStringCreateWithCString(NULL, key, kCFStringEncodingASCII); + + if (!cfKey) diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index ad3d3116a04a..2dbacaa7f02a 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -763,6 +763,7 @@ self: super: sha256 = "0zm9g0g1jvy79sgkvy0rjm6ywrdba2xjd1nsnjbxjccckbr6i396"; name = "revert-fb-changes-2.patch"; }) + ./darwin/bundle_main.patch ./darwin/stub.patch ]; From 77f296ec593b4e07b5bd3b50f15d48a0c65c0d77 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 25 Apr 2023 19:18:14 -0400 Subject: [PATCH 3/6] xquartz: Copy fonts to avoid ELOOP --- pkgs/servers/x11/xquartz/system-fonts.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/servers/x11/xquartz/system-fonts.nix b/pkgs/servers/x11/xquartz/system-fonts.nix index db47f8afe015..13670978ec0b 100644 --- a/pkgs/servers/x11/xquartz/system-fonts.nix +++ b/pkgs/servers/x11/xquartz/system-fonts.nix @@ -22,7 +22,7 @@ stdenv.mkDerivation { find $fontDirs -type f -o -type l | while read i; do j="''${i##*/}" if ! test -e "$out/share/X11-fonts/''${j}"; then - ln -s "$i" "$out/share/X11-fonts/''${j}"; + cp "$i" "$out/share/X11-fonts/''${j}"; fi; done; cd $out/share/X11-fonts/ From d018f767e169950f02aeb95802c972c7b58772fc Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 26 Apr 2023 01:25:34 -0400 Subject: [PATCH 4/6] xquartz: Fix package to be compatible with current xorg.xorgserver --- pkgs/servers/x11/xquartz/10-fontdir.sh | 7 + pkgs/servers/x11/xquartz/98-user.sh | 6 + pkgs/servers/x11/xquartz/X11 | 20 -- pkgs/servers/x11/xquartz/default.nix | 139 +++++++------- pkgs/servers/x11/xquartz/patch_plist.rb | 47 ----- pkgs/servers/x11/xquartz/privileged | 43 ----- pkgs/servers/x11/xquartz/startx | 232 ------------------------ pkgs/servers/x11/xquartz/xinitrc | 40 ---- 8 files changed, 76 insertions(+), 458 deletions(-) create mode 100755 pkgs/servers/x11/xquartz/10-fontdir.sh create mode 100755 pkgs/servers/x11/xquartz/98-user.sh delete mode 100755 pkgs/servers/x11/xquartz/X11 delete mode 100644 pkgs/servers/x11/xquartz/patch_plist.rb delete mode 100755 pkgs/servers/x11/xquartz/privileged delete mode 100755 pkgs/servers/x11/xquartz/startx delete mode 100755 pkgs/servers/x11/xquartz/xinitrc diff --git a/pkgs/servers/x11/xquartz/10-fontdir.sh b/pkgs/servers/x11/xquartz/10-fontdir.sh new file mode 100755 index 000000000000..616b530175e9 --- /dev/null +++ b/pkgs/servers/x11/xquartz/10-fontdir.sh @@ -0,0 +1,7 @@ +fontpath="@SYSTEM_FONTS@" +[ -e "$HOME"/.fonts/fonts.dir ] && fontpath="$fontpath,$HOME/.fonts" +[ -e "$HOME"/Library/Fonts/fonts.dir ] && fontpath="$fontpath,$HOME/Library/Fonts" +[ -e /Library/Fonts/fonts.dir ] && fontpath="$fontpath,/Library/Fonts" +[ -e /System/Library/Fonts/fonts.dir ] && fontpath="$fontpath,/System/Library/Fonts" +@XSET@ fp= "$fontpath" +unset fontpath diff --git a/pkgs/servers/x11/xquartz/98-user.sh b/pkgs/servers/x11/xquartz/98-user.sh new file mode 100755 index 000000000000..3d3c5611eb45 --- /dev/null +++ b/pkgs/servers/x11/xquartz/98-user.sh @@ -0,0 +1,6 @@ +if [ -d "${HOME}/.xinitrc.d" ] ; then + for f in "${HOME}"/.xinitrc.d/*.sh ; do + [ -x "$f" ] && . "$f" + done + unset f +fi diff --git a/pkgs/servers/x11/xquartz/X11 b/pkgs/servers/x11/xquartz/X11 deleted file mode 100755 index e6bb87fab3fe..000000000000 --- a/pkgs/servers/x11/xquartz/X11 +++ /dev/null @@ -1,20 +0,0 @@ -#!@shell@ - -set "$(dirname "$0")"/X11.bin "${@}" - -export XQUARTZ_DEFAULT_CLIENT="@DEFAULT_CLIENT@" -export XQUARTZ_DEFAULT_SHELL="@DEFAULT_SHELL@" -export XQUARTZ_DEFAULT_STARTX="@DEFAULT_STARTX@" -export FONTCONFIG_FILE="@FONTCONFIG_FILE@" - -if [ -x ~/.x11run ]; then - exec ~/.x11run "${@}" -fi - -case $(basename "${SHELL}") in - bash) exec -l "${SHELL}" --login -c 'exec "${@}"' - "${@}" ;; - ksh|sh|zsh) exec -l "${SHELL}" -c 'exec "${@}"' - "${@}" ;; - csh|tcsh) exec -l "${SHELL}" -c 'exec $argv:q' "${@}" ;; - es|rc) exec -l "${SHELL}" -l -c 'exec $*' "${@}" ;; - *) exec "${@}" ;; -esac diff --git a/pkgs/servers/x11/xquartz/default.nix b/pkgs/servers/x11/xquartz/default.nix index ad4d5603a135..3c2cf20eba54 100644 --- a/pkgs/servers/x11/xquartz/default.nix +++ b/pkgs/servers/x11/xquartz/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, buildEnv, makeFontsConf, gnused, writeScript, xorg, bashInteractive, xterm, makeWrapper, ruby +{ lib, stdenv, buildEnv, makeFontsConf, gnused, writeScript, xorg, bashInteractive, xterm, xcbuild, makeWrapper , quartz-wm, fontconfig, xlsfonts, xfontsel , ttf_bitstream_vera, freefont_ttf, liberation_ttf , shell ? "${bashInteractive}/bin/bash" @@ -46,13 +46,13 @@ let sed=${gnused}/bin/sed cp ${./org.nixos.xquartz.startx.plist} $tmpdir/$agentName - $sed -i "s|@LAUNCHD_STARTX@|$NIX_LINK/etc/X11/xinit/launchd_startx|" $tmpdir/$agentName + $sed -i "s|@LAUNCHD_STARTX@|$NIX_LINK/libexec/launchd_startx|" $tmpdir/$agentName $sed -i "s|@STARTX@|$NIX_LINK/bin/startx|" $tmpdir/$agentName $sed -i "s|@XQUARTZ@|$NIX_LINK/bin/Xquartz|" $tmpdir/$agentName cp ${./org.nixos.xquartz.privileged_startx.plist} $tmpdir/$daemonName - $sed -i "s|@PRIVILEGED_STARTX@|$NIX_LINK/lib/X11/xinit/privileged_startx|" $tmpdir/$daemonName - $sed -i "s|@PRIVILEGED_STARTX_D@|$NIX_LINK/lib/X11/xinit/privileged_startx.d|" $tmpdir/$daemonName + $sed -i "s|@PRIVILEGED_STARTX@|$NIX_LINK/libexec/privileged_startx|" $tmpdir/$daemonName + $sed -i "s|@PRIVILEGED_STARTX_D@|$NIX_LINK/etc/X11/xinit/privileged_startx.d|" $tmpdir/$daemonName sudo cp $tmpdir/$agentName /Library/LaunchAgents/$agentName sudo cp $tmpdir/$daemonName /Library/LaunchDaemons/$daemonName @@ -79,26 +79,22 @@ let inherit stdenv xorg fontDirs; }; # any X related programs expected to be available via $PATH - env = buildEnv { - name = "xquartz-env"; - pathsToLink = [ "/bin" ]; - paths = with xorg; [ - # non-xorg - quartz-wm xterm fontconfig - # xorg - xlsfonts xfontsel - bdftopcf fontutil iceauth libXpm lndir luit makedepend mkfontdir - mkfontscale sessreg setxkbmap smproxy twm x11perf xauth xbacklight xclock - xcmsdb xcursorgen xdm xdpyinfo xdriinfo xev xeyes xfs xgamma xhost - xinput xkbcomp xkbevd xkbutils xkill xlsatoms xlsclients xmessage xmodmap - xpr xprop xrandr xrdb xrefresh xset xsetroot xvinfo xwd xwininfo xwud - ]; - }; + pkgs = with xorg; [ + # non-xorg + quartz-wm xterm fontconfig + # xorg + xlsfonts xfontsel + bdftopcf fontutil iceauth libXpm lndir luit makedepend mkfontdir + mkfontscale sessreg setxkbmap smproxy twm x11perf xauth xbacklight xclock + xcmsdb xcursorgen xdm xdpyinfo xdriinfo xev xeyes xfs xgamma xhost + xinput xkbcomp xkbevd xkbutils xkill xlsatoms xlsclients xmessage xmodmap + xpr xprop xrandr xrdb xrefresh xset xsetroot xvinfo xwd xwininfo xwud + ]; in stdenv.mkDerivation { pname = "xquartz"; version = lib.getVersion xorg.xorgserver; - nativeBuildInputs = [ ruby makeWrapper ]; + nativeBuildInputs = [ makeWrapper ]; unpackPhase = "sourceRoot=."; @@ -117,74 +113,65 @@ in stdenv.mkDerivation { fontsConfPath=$out/etc/X11/fonts.conf cp ${fontsConf} $fontsConfPath - cp ${./startx} $out/bin/startx substituteInPlace $out/bin/startx \ - --replace "@shell@" "${stdenv.shell}" \ - --replace "@PATH@" "$out/bin:${env}" \ - --replace "@XAUTH@" "${xorg.xauth}/bin/xauth" \ - --replace "@FONT_CACHE@" "$out/bin/font_cache" \ - --replace "@PRIVILEGED_STARTX@" "$out/lib/X11/xinit/privileged_startx" \ - --replace "@DEFAULT_SERVER@" "$out/bin/Xquartz" \ - --replace "@DEFAULT_CLIENT@" "${xterm}/bin/xterm" \ - --replace "@XINIT@" "$out/bin/xinit" \ - --replace "@XINITRC@" "$out/etc/X11/xinit/xinitrc" \ - --replace "@FONTCONFIG_FILE@" "$fontsConfPath" + --replace "bindir=${xorg.xinit}/bin" "bindir=$out/bin" \ + --replace 'defaultserver=${xorg.xorgserver}/bin/X' "defaultserver=$out/bin/Xquartz" \ + --replace "${xorg.xinit}" "$out" \ + --replace "${xorg.xorgserver}" "$out" \ + --replace "eval xinit" "eval $out/bin/xinit" \ + --replace "sysclientrc=/etc/X11/xinit/xinitrc" "sysclientrc=$out/etc/X11/xinit/xinitrc" wrapProgram $out/bin/Xquartz \ - --set XQUARTZ_X11 $out/Applications/XQuartz.app/Contents/MacOS/X11 + --set XQUARTZ_APP $out/Applications/XQuartz.app defaultStartX="$out/bin/startx -- $out/bin/Xquartz" - ruby ${./patch_plist.rb} \ - ${lib.escapeShellArg (builtins.toXML { - XQUARTZ_DEFAULT_CLIENT = "${xterm}/bin/xterm"; - XQUARTZ_DEFAULT_SHELL = shell; - XQUARTZ_DEFAULT_STARTX = "@STARTX@"; - FONTCONFIG_FILE = "@FONTCONFIG_FILE@"; - })} \ - $out/Applications/XQuartz.app/Contents/Info.plist - substituteInPlace $out/Applications/XQuartz.app/Contents/Info.plist \ - --replace "@STARTX@" "$defaultStartX" \ - --replace "@FONTCONFIG_FILE@" "$fontsConfPath" + ${xcbuild}/bin/PlistBuddy $out/Applications/XQuartz.app/Contents/Info.plist < $out/etc/X11/xinit/xinitrc.d/99-quartz-wm.sh < /dev/null` - if [ "${check}" = "041777 0 0" ] ; then - success=1 - break - elif [ -n "${check}" ] ; then - saved=$(${MKTEMP} -d ${dir}-XXXXXXXX) - mv ${dir} ${saved} - echo "${dir} exists but is insecure. It has been moved into ${saved}" >&2 - fi - - # if $dir exists and is a symlink (ie protect against a race) - if ${MKTEMP} -d ${dir} >& /dev/null ; then - chmod 1777 $dir - chown root:wheel $dir - success=1 - break - fi - done - - if [ "${success}" -eq 0 ] ; then - echo "Could not successfully create ${dir}" >&2 - fi -done - -@FONT_CACHE@ -s & diff --git a/pkgs/servers/x11/xquartz/startx b/pkgs/servers/x11/xquartz/startx deleted file mode 100755 index b4afebce57c7..000000000000 --- a/pkgs/servers/x11/xquartz/startx +++ /dev/null @@ -1,232 +0,0 @@ -#!@shell@ - -# vim :set ts=4 sw=4 sts=4 et : - -# -# This is just a sample implementation of a slightly less primitive -# interface than xinit. It looks for user .xinitrc and .xserverrc -# files, then system xinitrc and xserverrc files, else lets xinit choose -# its default. The system xinitrc should probably do things like check -# for .Xresources files and merge them in, start up a window manager, -# and pop a clock and several xterms. -# -# Site administrators are STRONGLY urged to write nicer versions. -# - -unset DBUS_SESSION_BUS_ADDRESS -unset SESSION_MANAGER - - -# Bourne shell does not automatically export modified environment variables -# so export the new PATH just in case the user changes the shell -export PATH=@PATH@:$PATH - -export FONTCONFIG_FILE="@FONTCONFIG_FILE@" - -userclientrc=$HOME/.xinitrc -sysclientrc=@XINITRC@ - -userserverrc=$HOME/.xserverrc -sysserverrc=@XINITRC@ -defaultclient=@DEFAULT_CLIENT@ # xterm -defaultserver=@DEFAULT_SERVER@ -defaultclientargs="" -defaultserverargs="" -defaultdisplay=":0" -clientargs="" -serverargs="" - -export X11_PREFS_DOMAIN=org.nixos.xquartz".X11" - -# Initialize defaults (this will cut down on "safe" error messages) -if ! /usr/bin/defaults read $X11_PREFS_DOMAIN cache_fonts > /dev/null 2>&1 ; then - /usr/bin/defaults write $X11_PREFS_DOMAIN cache_fonts -bool true -fi - -if ! /usr/bin/defaults read $X11_PREFS_DOMAIN no_auth > /dev/null 2>&1 ; then - /usr/bin/defaults write $X11_PREFS_DOMAIN no_auth -bool false -fi - -if ! /usr/bin/defaults read $X11_PREFS_DOMAIN nolisten_tcp > /dev/null 2>&1 ; then - /usr/bin/defaults write $X11_PREFS_DOMAIN nolisten_tcp -bool true -fi - -# First, start caching fonts -if [ x`/usr/bin/defaults read $X11_PREFS_DOMAIN cache_fonts` = x1 ] ; then - @FONT_CACHE@ & -fi - -# a race to create /tmp/.X11-unix -@PRIVILEGED_STARTX@ - -if [ x`/usr/bin/defaults read $X11_PREFS_DOMAIN no_auth` = x0 ] ; then - enable_xauth=1 -else - enable_xauth=0 -fi - -if [ x`defaults read $X11_PREFS_DOMAIN nolisten_tcp` = x1 ] ; then - defaultserverargs="$defaultserverargs -nolisten tcp" -fi - -# The second check is the real one. The first is to hopefully avoid -# needless syslog spamming. -if /usr/bin/defaults read $X11_PREFS_DOMAIN 2> /dev/null | grep -q 'dpi' && /usr/bin/defaults read $X11_PREFS_DOMAIN dpi > /dev/null 2>&1 ; then - defaultserverargs="$defaultserverargs -dpi `/usr/bin/defaults read $X11_PREFS_DOMAIN dpi`" -fi - -# Automatically determine an unused $DISPLAY -d=0 -while true ; do - [ -e /tmp/.X$d-lock ] || break - d=$(($d + 1)) -done -defaultdisplay=":$d" -unset d - -whoseargs="client" -while [ x"$1" != x ]; do - case "$1" in - # '' required to prevent cpp from treating "/*" as a C comment. - /''*|\./''*) - if [ "$whoseargs" = "client" ]; then - if [ x"$client" = x ] && [ x"$clientargs" = x ]; then - client="$1" - else - clientargs="$clientargs $1" - fi - else - if [ x"$server" = x ] && [ x"$serverargs" = x ]; then - server="$1" - else - serverargs="$serverargs $1" - fi - fi - ;; - --) - whoseargs="server" - ;; - *) - if [ "$whoseargs" = "client" ]; then - clientargs="$clientargs $1" - else - # display must be the FIRST server argument - if [ x"$serverargs" = x ] && \ - expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then - display="$1" - else - serverargs="$serverargs $1" - fi - fi - ;; - esac - shift -done - -# process client arguments -if [ x"$client" = x ]; then - client=$defaultclient - - # For compatibility reasons, only use startxrc if there were no client command line arguments - if [ x"$clientargs" = x ]; then - if [ -f "$userclientrc" ]; then - client=$userclientrc - elif [ -f "$sysclientrc" ]; then - client=$sysclientrc - fi - fi -fi - -# if no client arguments, use defaults -if [ x"$clientargs" = x ]; then - clientargs=$defaultclientargs -fi - -# process server arguments -if [ x"$server" = x ]; then - server=$defaultserver - - # For compatibility reasons, only use xserverrc if there were no server command line arguments - if [ x"$serverargs" = x -a x"$display" = x ]; then - if [ -f "$userserverrc" ]; then - server=$userserverrc - elif [ -f "$sysserverrc" ]; then - server=$sysserverrc - fi - fi -fi - -# if no server arguments, use defaults -if [ x"$serverargs" = x ]; then - serverargs=$defaultserverargs -fi - -# if no display, use default -if [ x"$display" = x ]; then - display=$defaultdisplay -fi - -if [ x"$enable_xauth" = x1 ] ; then - if [ x"$XAUTHORITY" = x ]; then - XAUTHORITY=$HOME/.Xauthority - export XAUTHORITY - fi - - removelist= - - # set up default Xauth info for this machine - hostname=`/bin/hostname` - - authdisplay=${display:-:0} - - mcookie=`/usr/bin/openssl rand -hex 16` - - if test x"$mcookie" = x; then - echo "Couldn't create cookie" - exit 1 - fi - dummy=0 - - # create a file with auth information for the server. ':0' is a dummy. - xserverauthfile=$HOME/.serverauth.$$ - trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM - @XAUTH@ -q -f "$xserverauthfile" << EOF -add :$dummy . $mcookie -EOF - - xserverauthfilequoted=$(echo ${xserverauthfile} | sed "s/'/'\\\\''/g") - serverargs=${serverargs}" -auth '"${xserverauthfilequoted}"'" - - # now add the same credentials to the client authority file - # if '$displayname' already exists do not overwrite it as another - # server man need it. Add them to the '$xserverauthfile' instead. - for displayname in $authdisplay $hostname$authdisplay; do - authcookie=`@XAUTH@ list "$displayname" \ - | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null; - if [ "z${authcookie}" = "z" ] ; then - @XAUTH@ -q << EOF -add $displayname . $mcookie -EOF - removelist="$displayname $removelist" - else - dummy=$(($dummy+1)); - @XAUTH@ -q -f "$xserverauthfile" << EOF -add :$dummy . $authcookie -EOF - fi - done -fi - -eval @XINIT@ \"$client\" $clientargs -- \"$server\" $display $serverargs -retval=$? - -if [ x"$enable_xauth" = x1 ] ; then - if [ x"$removelist" != x ]; then - @XAUTH@ remove $removelist - fi - if [ x"$xserverauthfile" != x ]; then - rm -f "$xserverauthfile" - fi -fi - -exit $retval diff --git a/pkgs/servers/x11/xquartz/xinitrc b/pkgs/servers/x11/xquartz/xinitrc deleted file mode 100755 index 276aeca7c846..000000000000 --- a/pkgs/servers/x11/xquartz/xinitrc +++ /dev/null @@ -1,40 +0,0 @@ -#!@shell@ - -export PATH=@PATH@:$PATH - -userresources=$HOME/.Xresources -usermodmap=$HOME/.Xmodmap - -# Fix ridiculously slow key repeat. -@XSET@ r rate - -# merge in defaults and keymaps - -if [ -f "$userresources" ]; then - if [ -x /usr/bin/cpp ] ; then - @XRDB@ -merge "$userresources" - else - @XRDB@ -nocpp -merge "$userresources" - fi -fi - -if [ -f "$usermodmap" ]; then - @XMODMAP@ "$usermodmap" -fi - -fontpath="@SYSTEM_FONTS@" -[ -e "$HOME"/.fonts/fonts.dir ] && fontpath="$fontpath,$HOME/.fonts" -[ -e "$HOME"/Library/Fonts/fonts.dir ] && fontpath="$fontpath,$HOME/Library/Fonts" -[ -e /Library/Fonts/fonts.dir ] && fontpath="$fontpath,/Library/Fonts" -[ -e /System/Library/Fonts/fonts.dir ] && fontpath="$fontpath,/System/Library/Fonts" -@XSET@ fp= "$fontpath" -unset fontpath - -if [ -d "${HOME}/.xinitrc.d" ] ; then - for f in "${HOME}"/.xinitrc.d/*.sh ; do - [ -x "$f" ] && . "$f" - done - unset f -fi - -exec @QUARTZ_WM@ From 9ae8af51c50dda225f6a566befcdf33b5578e11d Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 26 Apr 2023 02:08:44 -0400 Subject: [PATCH 5/6] xquartz: Allow extra font directories to be passed --- pkgs/servers/x11/xquartz/default.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/servers/x11/xquartz/default.nix b/pkgs/servers/x11/xquartz/default.nix index 3c2cf20eba54..cdb2122a612d 100644 --- a/pkgs/servers/x11/xquartz/default.nix +++ b/pkgs/servers/x11/xquartz/default.nix @@ -2,6 +2,8 @@ , quartz-wm, fontconfig, xlsfonts, xfontsel , ttf_bitstream_vera, freefont_ttf, liberation_ttf , shell ? "${bashInteractive}/bin/bash" +, unfreeFonts ? false +, extraFontDirs ? [] }: # ------------ @@ -60,15 +62,16 @@ let sudo launchctl load -w /Library/LaunchDaemons/$daemonName ''; fontDirs = [ - xorg.fontbhlucidatypewriter100dpi - xorg.fontbhlucidatypewriter75dpi ttf_bitstream_vera freefont_ttf liberation_ttf - xorg.fontbh100dpi xorg.fontmiscmisc xorg.fontcursormisc - ]; + ] ++ lib.optionals unfreeFonts [ + xorg.fontbhlucidatypewriter100dpi + xorg.fontbhlucidatypewriter75dpi + xorg.fontbh100dpi + ] ++ extraFontDirs; fontsConf = makeFontsConf { fontDirectories = fontDirs ++ [ "/Library/Fonts" From 65601cbb215591061ae37e0cc2d1b27b355f0fec Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 3 May 2023 00:21:49 -0400 Subject: [PATCH 6/6] xorg.xorgserver: Use substitute in patches instead of postPatch --- pkgs/servers/x11/xorg/overrides.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index 2dbacaa7f02a..d22155c97a4b 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -1,6 +1,6 @@ { abiCompat ? null, callPackage, - lib, stdenv, makeWrapper, fetchurl, fetchpatch, fetchFromGitLab, buildPackages, + lib, stdenv, makeWrapper, fetchurl, fetchpatch, fetchFromGitLab, buildPackages, substitute, automake, autoconf, libiconv, libtool, intltool, freetype, tradcpp, fontconfig, meson, ninja, ed, fontforge, libGL, spice-protocol, zlib, libGLU, dbus, libunwind, libdrm, netbsd, @@ -764,14 +764,12 @@ self: super: name = "revert-fb-changes-2.patch"; }) ./darwin/bundle_main.patch - ./darwin/stub.patch + (substitute { + src = ./darwin/stub.patch; + replacements = ["--subst-var-by" "XQUARTZ_APP" "${placeholder "out"}/Applications/XQuartz.app"]; + }) ]; - postPatch = attrs.postPatch + '' - substituteInPlace hw/xquartz/mach-startup/stub.c \ - --subst-var-by XQUARTZ_APP "$out/Applications/XQuartz.app" - ''; - configureFlags = [ # note: --enable-xquartz is auto "CPPFLAGS=-I${./darwin/dri}"