diff options
Diffstat (limited to 'nixpkgs/pkgs/servers/x11/xquartz')
7 files changed, 520 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/x11/xquartz/10-fontdir.sh b/nixpkgs/pkgs/servers/x11/xquartz/10-fontdir.sh new file mode 100755 index 000000000000..616b530175e9 --- /dev/null +++ b/nixpkgs/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/nixpkgs/pkgs/servers/x11/xquartz/98-user.sh b/nixpkgs/pkgs/servers/x11/xquartz/98-user.sh new file mode 100755 index 000000000000..3d3c5611eb45 --- /dev/null +++ b/nixpkgs/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/nixpkgs/pkgs/servers/x11/xquartz/default.nix b/nixpkgs/pkgs/servers/x11/xquartz/default.nix new file mode 100644 index 000000000000..93b2869f8d2b --- /dev/null +++ b/nixpkgs/pkgs/servers/x11/xquartz/default.nix @@ -0,0 +1,183 @@ +{ 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" +, unfreeFonts ? false +, extraFontDirs ? [] +}: + +# ------------ +# Installation +# ------------ +# +# First, assuming you've previously installed XQuartz from macosforge.com, +# unload and remove the existing launch agents: +# +# $ sudo launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist +# $ sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist +# $ sudo rm /Library/LaunchAgents/org.macosforge.xquartz.startx.plist +# $ sudo rm /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist +# +# (You will need to log out for the above changes to take effect.) +# +# Then install xquartz from nixpkgs: +# +# $ nix-env -i xquartz +# $ xquartz-install +# +# You'll also want to add the following to your shell's profile (after you +# source nix.sh, so $NIX_LINK points to your user profile): +# +# if [ "$(uname)" = "Darwin" -a -n "$NIX_LINK" -a -f $NIX_LINK/etc/X11/fonts.conf ]; then +# export FONTCONFIG_FILE=$NIX_LINK/etc/X11/fonts.conf +# fi + +# A note about dependencies: +# Xquartz wants to exec XQuartz.app, XQuartz.app wants to exec xstart, and +# xstart wants to exec Xquartz, so we must bundle all three to prevent a cycle. +# Coincidentally, this also makes it trivial to install launch agents/daemons +# that point into the user's profile. + +let + installer = writeScript "xquartz-install" '' + NIX_LINK=$HOME/.nix-profile + + tmpdir=$(/usr/bin/mktemp -d $TMPDIR/xquartz-installer-XXXXXXXX) + agentName=org.nixos.xquartz.startx.plist + daemonName=org.nixos.xquartz.privileged_startx.plist + sed=${gnused}/bin/sed + + cp ${./org.nixos.xquartz.startx.plist} $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/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 + sudo launchctl load -w /Library/LaunchAgents/$agentName + sudo launchctl load -w /Library/LaunchDaemons/$daemonName + ''; + fontDirs = [ + ttf_bitstream_vera + freefont_ttf + liberation_ttf + xorg.fontmiscmisc + xorg.fontcursormisc + ] ++ lib.optionals unfreeFonts [ + xorg.fontbhlucidatypewriter100dpi + xorg.fontbhlucidatypewriter75dpi + xorg.fontbh100dpi + ] ++ extraFontDirs; + fontsConf = makeFontsConf { + fontDirectories = fontDirs ++ [ + "/Library/Fonts" + "~/Library/Fonts" + ]; + }; + fonts = import ./system-fonts.nix { + inherit stdenv xorg fontDirs; + }; + # any X related programs expected to be available via $PATH + 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 = [ makeWrapper ]; + + unpackPhase = "sourceRoot=."; + + dontBuild = true; + + installPhase = '' + cp -rT ${xorg.xinit} $out + chmod -R u+w $out + cp -rT ${xorg.xorgserver} $out + chmod -R u+w $out + + cp ${installer} $out/bin/xquartz-install + + rm -rf $out/LaunchAgents $out/LaunchDaemons + + fontsConfPath=$out/etc/X11/fonts.conf + cp ${fontsConf} $fontsConfPath + + substituteInPlace $out/bin/startx \ + --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_APP $out/Applications/XQuartz.app + + defaultStartX="$out/bin/startx -- $out/bin/Xquartz" + + ${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 + + 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 \ + --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; [ ]; + license = licenses.mit; + }; +} diff --git a/nixpkgs/pkgs/servers/x11/xquartz/font_cache b/nixpkgs/pkgs/servers/x11/xquartz/font_cache new file mode 100755 index 000000000000..b1191980d77f --- /dev/null +++ b/nixpkgs/pkgs/servers/x11/xquartz/font_cache @@ -0,0 +1,240 @@ +#!@shell@ + +export PATH=@PATH@:$PATH + +export FONTCONFIG_FILE="@FONTCONFIG_FILE@" +ENCODINGSDIR="@ENCODINGSDIR@" +FC_LOCKFILE="" + +# Are we caching system fonts or user fonts? +system=0 + +# Are we including OSX font dirs ({/,~/,/System/}Library/Fonts) +osxfonts=1 + +# Do we want to force a recache? +force=0 + +# How noisy are we? +verbose=0 + +# Check if the data in the given directory is newer than its cache +check_dirty() { + local dir=$1 + local fontfiles="" + local retval=1 + + # If the dir does not exist, we just exit + if [[ ! -d "${dir}" ]]; then + return 1 + fi + + # Create a list of all files in the dir + # Filter out config / cache files. Ugly... counting down the day until + # xfs finally goes away + fontfiles="$(find ${dir}/ -maxdepth 1 -type f | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')" + + # Fonts were deleted (or never there). Kill off the caches + if [[ -z "${fontfiles}" ]] ; then + local f + for f in "${dir}"/fonts.* "${dir}"/encodings.dir; do + if [[ -f ${f} ]] ; then + rm -f "${f}" + fi + done + return 1 + fi + + # Force a recache + if [[ ${force} == 1 ]] ; then + retval=0 + fi + + # If we don't have our caches, we are dirty + if [[ ! -f "${dir}/fonts.list" || ! -f "${dir}/fonts.dir" || ! -f "${dir}/encodings.dir" ]]; then + retval=0 + fi + + # Check that no files were added or removed.... + if [[ "${retval}" -ne 0 && "$(cat ${dir}/fonts.list)" != "${fontfiles}" ]] ; then + retval=0 + fi + + # Check that no files were updated.... + if [[ "${retval}" -ne 0 ]] ; then + local changed="$(find ${dir}/ -type f -cnewer ${dir}/fonts.dir | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')" + + if [[ -n "${changed}" ]] ; then + retval=0 + fi + fi + + # Recreate fonts.list since something changed + if [[ "${retval}" == 0 ]] ; then + echo "${fontfiles}" > "${dir}"/fonts.list + fi + + return ${retval} +} + +get_fontdirs() { + local d + if [[ $system == 1 ]] ; then + if [[ $osxfonts == 1 ]] ; then + find {/System/,/}Library/Fonts -type d + fi + else + if [[ $osxfonts == 1 && -d "${HOME}/Library/Fonts" ]] ; then + find "${HOME}/Library/Fonts" -type d + fi + + if [[ -d "${HOME}/.fonts" ]] ; then + find "${HOME}/.fonts" -type d + fi + fi +} + +setup_fontdirs() { + local x="" + local fontdirs="" + local changed="no" + + umask 022 + + if [[ $system == 1 ]] ; then + echo "font_cache: Scanning system font directories to generate X11 font caches" + else + echo "font_cache: Scanning user font directories to generate X11 font caches" + fi + + OIFS=$IFS + IFS=' +' + for x in $(get_fontdirs) ; do + if [[ -d "${x}" ]] && check_dirty "${x}" ; then + if [[ -z "${fontdirs}" ]] ; then + fontdirs="${x}" + else + fontdirs="${fontdirs}${IFS}${x}" + fi + fi + done + + if [[ -n "${fontdirs}" ]] ; then + echo "font_cache: Making fonts.dir for updated directories." + for x in ${fontdirs} ; do + if [[ $verbose == 1 ]] ; then + echo "font_cache: ${x}" + fi + + # First, generate fonts.scale for scaleable fonts that might be there + @MKFONTSCALE@ \ + -a $ENCODINGSDIR/encodings.dir \ + -a $ENCODINGSDIR/large/encodings.dir \ + -- ${x} + + # Next, generate fonts.dir + if [[ $verbose == 1 ]] ; then + @MKFONTDIR@ \ + -e $ENCODINGSDIR \ + -e $ENCODINGSDIR/large \ + -- ${x} + else + @MKFONTDIR@ \ + -e $ENCODINGSDIR \ + -e $ENCODINGSDIR/large \ + -- ${x} > /dev/null + fi + done + fi + IFS=$OIFS + + # Finally, update fontconfig's cache + echo "font_cache: Updating FC cache" + if [[ $system == 1 ]] ; then + @FC_CACHE@ -s \ + $([[ $force == 1 ]] && echo "-f -r") \ + $([[ $verbose == 1 ]] && echo "-v") + else + @FC_CACHE@ \ + $([[ $force == 1 ]] && echo "-f -r") \ + $([[ $verbose == 1 ]] && echo "-v") + fi + echo "font_cache: Done" +} + +do_usage() { + echo "font_cache [options]" + echo " -f, --force : Force cache recreation" + echo " -n, --no-osxfonts : Just cache X11 font directories" + echo " (-n just pertains to XFont cache, not fontconfig)" + echo " -s, --system : Cache system font dirs instead of user dirs" + echo " -v, --verbose : Verbose Output" +} + +cleanup() { + [[ -r "${FC_LOCKFILE}" ]] && rm -f "${FC_LOCKFILE}" + exit 1 +} + +while [[ $# -gt 0 ]] ; do + case $1 in + -s|--system) system=1 ;; + -f|--force) force=1 ;; + -v|--verbose) verbose=1 ;; + -n|--no-osxfonts) osxfonts=0 ;; + --help) do_usage ; exit 0 ;; + *) do_usage ; exit 1 ;; + esac + shift +done + +if [[ $system == 1 ]] ; then + FC_LOCKFILE="/tmp/font_cache.$UID.lock" +elif [[ -w "${TMPDIR}" ]] ; then + FC_LOCKFILE="${TMPDIR}/font_cache.lock" +elif [[ -w "/tmp" ]] ; then + FC_LOCKFILE="/tmp/font_cache.$UID.lock" +else + FC_LOCKFILE="${HOME}/.font_cache.lock" +fi + +if [[ -x /usr/bin/lockfile ]] ; then + if /usr/bin/lockfile -r 0 -l 240 -s 4 -! "${FC_LOCKFILE}" ; then + echo "font_cache is already running." >&2 + echo "If you believe this to be erroneous, please remove ${FC_LOCKFILE}." >&2 + exit 1 + fi +else + if [[ -r "${FC_LOCKFILE}" ]] ; then + read OLD_PID < "${FC_LOCKFILE}" + if kill -0 ${OLD_PID} >& /dev/null ; then + echo "font_cache is already running with PID ${OLD_PID}." >&2 + echo "If you believe this to be erroneous, please remove ${FC_LOCKFILE}." >&2 + exit 1 + fi + + echo "Removing stale ${FC_LOCKFILE}" >&2 + rm -f "${FC_LOCKFILE}" + fi + + echo $$ > "${FC_LOCKFILE}" + + if [[ ! -r "${FC_LOCKFILE}" ]] ; then + echo "Unable to write to ${FC_LOCKFILE}." >&2 + exit 1 + fi + + # Now make sure we didn't collide mid-air + read OLD_PID < "${FC_LOCKFILE}" + if [[ $$ != ${OLD_PID} ]] ; then + echo "font_cache is already running with PID ${OLD_PID}." >&2 + exit 1 + fi +fi + +trap cleanup SIGINT SIGQUIT SIGABRT SIGTERM + +setup_fontdirs + +rm -f "${FC_LOCKFILE}" diff --git a/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.privileged_startx.plist b/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.privileged_startx.plist new file mode 100644 index 000000000000..190b383676d4 --- /dev/null +++ b/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.privileged_startx.plist @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>Label</key> + <string>org.nixos.xquartz.privileged_startx</string> + <key>ProgramArguments</key> + <array> + <string>@PRIVILEGED_STARTX@</string> + <string>-d</string> + <string>@PRIVILEGED_STARTX_D@</string> + </array> + <key>MachServices</key> + <dict> + <key>org.nixos.xquartz.privileged_startx</key> + <true/> + </dict> + <key>TimeOut</key> + <integer>120</integer> + <key>EnableTransactions</key> + <true/> + </dict> +</plist> diff --git a/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.startx.plist b/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.startx.plist new file mode 100644 index 000000000000..7a95916da165 --- /dev/null +++ b/nixpkgs/pkgs/servers/x11/xquartz/org.nixos.xquartz.startx.plist @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>Label</key> + <string>org.nixos.xquartz.startx</string> + <key>ProgramArguments</key> + <array> + <string>@LAUNCHD_STARTX@</string> + <string>@STARTX@</string> + <string>--</string> + <string>@XQUARTZ@</string> + </array> + <key>Sockets</key> + <dict> + <key>org.nixos.xquartz:0</key> + <dict> + <key>SecureSocketWithKey</key> + <string>DISPLAY</string> + </dict> + </dict> + <key>ServiceIPC</key> + <true/> + <key>EnableTransactions</key> + <true/> + </dict> +</plist> diff --git a/nixpkgs/pkgs/servers/x11/xquartz/system-fonts.nix b/nixpkgs/pkgs/servers/x11/xquartz/system-fonts.nix new file mode 100644 index 000000000000..13670978ec0b --- /dev/null +++ b/nixpkgs/pkgs/servers/x11/xquartz/system-fonts.nix @@ -0,0 +1,34 @@ +{ stdenv, xorg, fontDirs }: + +stdenv.mkDerivation { + name = "xquartz-system-fonts"; + buildInputs = [ + xorg.mkfontdir xorg.mkfontscale + ]; + buildCommand = '' + source $stdenv/setup + + for i in ${toString fontDirs} ; do + if [ -d $i/ ]; then + list="$list $i"; + fi; + done + list=$(find $list -name fonts.dir -o -name '*.ttf' -o -name '*.otf'); + fontDirs='''; + for i in $list ; do + fontDirs="$fontDirs $(dirname $i)"; + done; + mkdir -p $out/share/X11-fonts/; + find $fontDirs -type f -o -type l | while read i; do + j="''${i##*/}" + if ! test -e "$out/share/X11-fonts/''${j}"; then + cp "$i" "$out/share/X11-fonts/''${j}"; + fi; + done; + cd $out/share/X11-fonts/ + rm -f fonts.dir fonts.scale fonts.alias + mkfontdir + mkfontscale + cat $( find ${xorg.fontalias}/ -name fonts.alias) >fonts.alias + ''; +} |