Unverified Commit d018f767 authored by Quentin Smith's avatar Quentin Smith
Browse files

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

parent 77f296ec
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
#!@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"
@@ -29,12 +5,3 @@ fontpath="@SYSTEM_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@
+6 −0
Original line number Diff line number Diff line
if [ -d "${HOME}/.xinitrc.d" ] ; then
    for f in "${HOME}"/.xinitrc.d/*.sh ; do
        [ -x "$f" ] && . "$f"
    done
    unset f
fi

pkgs/servers/x11/xquartz/X11

deleted100755 → 0
+0 −20
Original line number Diff line number Diff line
#!@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
+64 −77
Original line number Diff line number Diff line
{ 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,10 +79,7 @@ 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; [
  pkgs = with xorg; [
    # non-xorg
    quartz-wm xterm fontconfig
    # xorg
@@ -93,12 +90,11 @@ let
    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"

    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"
    ${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 \
      --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 ];
+0 −47
Original line number Diff line number Diff line
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])
Loading