xquartz: Fix package to be compatible with current xorg.xorgserver

This commit is contained in:
Quentin Smith 2023-04-26 01:25:34 -04:00
parent 77f296ec59
commit d018f767e1
No known key found for this signature in database
GPG key ID: 04EE05A8FCEFB697
8 changed files with 76 additions and 458 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <<EOF
Add :LSEnvironment dictionary
Add :LSEnvironment:XQUARTZ_DEFAULT_CLIENT string "${xterm}/bin/xterm"
Add :LSEnvironment:XQUARTZ_DEFAULT_SHELL string "${shell}"
Add :LSEnvironment:XQUARTZ_DEFAULT_STARTX string "$defaultStartX"
Add :LSEnvironment:FONTCONFIG_FILE string "$fontsConfPath"
Save
EOF
mkdir -p $out/lib/X11/xinit/privileged_startx.d
cp ${./privileged} $out/lib/X11/xinit/privileged_startx.d/privileged
substituteInPlace $out/lib/X11/xinit/privileged_startx.d/privileged \
--replace "@shell@" "${stdenv.shell}" \
--replace "@PATH@" "$out/bin:${env}" \
--replace "@FONTCONFIG_FILE@" "$fontsConfPath" \
--replace "@FONT_CACHE@" "$out/bin/font_cache"
substituteInPlace $out/etc/X11/xinit/xinitrc \
--replace ${xorg.xinit} $out \
--replace xmodmap ${xorg.xmodmap}/bin/xmodmap \
--replace xrdb ${xorg.xrdb}/bin/xrdb
mkdir -p $out/etc/X11/xinit/xinitrc.d
cp ${./10-fontdir.sh} $out/etc/X11/xinit/xinitrc.d/10-fontdir.sh
substituteInPlace $out/etc/X11/xinit/xinitrc.d/10-fontdir.sh \
--subst-var-by "SYSTEM_FONTS" "${fonts}/share/X11-fonts/" \
--subst-var-by "XSET" "${xorg.xset}/bin/xset"
cp ${./98-user.sh} $out/etc/X11/xinit/xinitrc.d/98-user.sh
cat > $out/etc/X11/xinit/xinitrc.d/99-quartz-wm.sh <<EOF
exec ${quartz-wm}/bin/quartz-wm
EOF
chmod +x $out/etc/X11/xinit/xinitrc.d/99-quartz-wm.sh
substituteInPlace $out/etc/X11/xinit/privileged_startx.d/20-font_cache \
--replace ${xorg.xinit} $out
cp ${./font_cache} $out/bin/font_cache
substituteInPlace $out/bin/font_cache \
--replace "@shell@" "${stdenv.shell}" \
--replace "@PATH@" "$out/bin:${env}" \
--replace "@ENCODINGSDIR@" "${xorg.encodings}/share/fonts/X11/encodings" \
--replace "@MKFONTDIR@" "${xorg.mkfontdir}/bin/mkfontdir" \
--replace "@MKFONTSCALE@" "${xorg.mkfontscale}/bin/mkfontscale" \
--replace "@FC_CACHE@" "${fontconfig.bin}/bin/fc-cache" \
--replace "@FONTCONFIG_FILE@" "$fontsConfPath"
cp ${./xinitrc} $out/etc/X11/xinit/xinitrc
substituteInPlace $out/etc/X11/xinit/xinitrc \
--replace "@shell@" "${stdenv.shell}" \
--replace "@PATH@" "$out/bin:${env}" \
--replace "@XSET@" "${xorg.xset}/bin/xset" \
--replace "@XMODMAP@" "${xorg.xmodmap}/bin/xmodmap" \
--replace "@XRDB@" "${xorg.xrdb}/bin/xrdb" \
--replace "@SYSTEM_FONTS@" "${fonts}/share/X11-fonts/" \
--replace "@QUARTZ_WM@" "${quartz-wm}/bin/quartz-wm" \
--replace "@FONTCONFIG_FILE@" "$fontsConfPath"
cp ${./X11} $out/Applications/XQuartz.app/Contents/MacOS/X11
substituteInPlace $out/Applications/XQuartz.app/Contents/MacOS/X11 \
--replace "@shell@" "${stdenv.shell}" \
--replace "@DEFAULT_SHELL@" "${shell}" \
--replace "@DEFAULT_STARTX@" "$defaultStartX" \
--replace "@DEFAULT_CLIENT@" "${xterm}/bin/xterm" \
--replace "@FONTCONFIG_FILE@" "$fontsConfPath"
--subst-var-by "shell" "${stdenv.shell}" \
--subst-var-by "PATH" "$out/bin" \
--subst-var-by "ENCODINGSDIR" "${xorg.encodings}/share/fonts/X11/encodings" \
--subst-var-by "MKFONTDIR" "${xorg.mkfontdir}/bin/mkfontdir" \
--subst-var-by "MKFONTSCALE" "${xorg.mkfontscale}/bin/mkfontscale" \
--subst-var-by "FC_CACHE" "${fontconfig.bin}/bin/fc-cache" \
--subst-var-by "FONTCONFIG_FILE" "$fontsConfPath"
'';
passthru = {
inherit pkgs;
};
meta = with lib; {
platforms = platforms.darwin;
maintainers = with maintainers; [ cstrahan ];

View file

@ -1,47 +0,0 @@
require 'rexml/document'
# This script is for setting environment variables in OSX applications.
#
# This script takes two arguments:
# 1) A Nix attrset serialized via `builtins.toXML'
# 2) The path to an OSX app's Info.plist file.
def main(serialized_attrs, plist_path)
env = attrs_to_hash(serialized_attrs)
doc = REXML::Document.new(File.open(plist_path, &:read))
topmost_dict = doc.root.elements.detect { |e| e.name == "dict" }
topmost_dict.add_element("key").tap do |key|
key.text = "LSEnvironment"
end
topmost_dict.add_element(env_to_dict(env))
formatter = REXML::Formatters::Pretty.new(2)
formatter.compact = true
formatter.write(doc, File.open(plist_path, "w"))
end
# Convert a `builtins.toXML' serialized attrs to a hash.
# This assumes the values are strings.
def attrs_to_hash(serialized_attrs)
hash = {}
env_vars = REXML::Document.new(serialized_attrs)
env_vars.root.elements[1].elements.each do |attr|
name = attr.attribute("name")
value = attr.elements.first.attribute("value")
hash[name] = value
end
hash
end
def env_to_dict(env)
dict = REXML::Element.new("dict")
env.each do |k, v|
key = dict.add_element("key")
key.text = k
string = dict.add_element("string")
string.text = v
end
dict
end
main(ARGV[0], ARGV[1])

View file

@ -1,43 +0,0 @@
#!@shell@
export PATH=@PATH@:$PATH
export FONTCONFIG_FILE="@FONTCONFIG_FILE@"
# Our usage of mktemp fails with GNU, so prefer /usr/bin to hopefully
# get BSD mktemp
if [ -x /usr/bin/mktemp ] ; then
MKTEMP=/usr/bin/mktemp
else
MKTEMP=mktemp
fi
STAT=/usr/bin/stat
for dir in /tmp/.ICE-unix /tmp/.X11-unix /tmp/.font-unix ; do
success=0
for attempt in 1 2 3 4 5 ; do
check=`${STAT} -f '%#p %u %g' ${dir} 2> /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 &

View file

@ -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

View file

@ -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@