1 { lib, stdenv, buildEnv, makeFontsConf, gnused, writeScript, xorg, bashInteractive, xterm, xcbuild, makeWrapper
2 , quartz-wm, fontconfig, xlsfonts, xfontsel
3 , ttf_bitstream_vera, freefont_ttf, liberation_ttf
4 , shell ? "${bashInteractive}/bin/bash"
13 # First, assuming you've previously installed XQuartz from macosforge.com,
14 # unload and remove the existing launch agents:
16 # $ sudo launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
17 # $ sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist
18 # $ sudo rm /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
19 # $ sudo rm /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist
21 # (You will need to log out for the above changes to take effect.)
23 # Then install xquartz from nixpkgs:
25 # $ nix-env -i xquartz
28 # You'll also want to add the following to your shell's profile (after you
29 # source nix.sh, so $NIX_LINK points to your user profile):
31 # if [ "$(uname)" = "Darwin" -a -n "$NIX_LINK" -a -f $NIX_LINK/etc/X11/fonts.conf ]; then
32 # export FONTCONFIG_FILE=$NIX_LINK/etc/X11/fonts.conf
35 # A note about dependencies:
36 # Xquartz wants to exec XQuartz.app, XQuartz.app wants to exec xstart, and
37 # xstart wants to exec Xquartz, so we must bundle all three to prevent a cycle.
38 # Coincidentally, this also makes it trivial to install launch agents/daemons
39 # that point into the user's profile.
42 installer = writeScript "xquartz-install" ''
43 NIX_LINK=$HOME/.nix-profile
45 tmpdir=$(/usr/bin/mktemp -d $TMPDIR/xquartz-installer-XXXXXXXX)
46 agentName=org.nixos.xquartz.startx.plist
47 daemonName=org.nixos.xquartz.privileged_startx.plist
50 cp ${./org.nixos.xquartz.startx.plist} $tmpdir/$agentName
51 $sed -i "s|@LAUNCHD_STARTX@|$NIX_LINK/libexec/launchd_startx|" $tmpdir/$agentName
52 $sed -i "s|@STARTX@|$NIX_LINK/bin/startx|" $tmpdir/$agentName
53 $sed -i "s|@XQUARTZ@|$NIX_LINK/bin/Xquartz|" $tmpdir/$agentName
55 cp ${./org.nixos.xquartz.privileged_startx.plist} $tmpdir/$daemonName
56 $sed -i "s|@PRIVILEGED_STARTX@|$NIX_LINK/libexec/privileged_startx|" $tmpdir/$daemonName
57 $sed -i "s|@PRIVILEGED_STARTX_D@|$NIX_LINK/etc/X11/xinit/privileged_startx.d|" $tmpdir/$daemonName
59 sudo cp $tmpdir/$agentName /Library/LaunchAgents/$agentName
60 sudo cp $tmpdir/$daemonName /Library/LaunchDaemons/$daemonName
61 sudo launchctl load -w /Library/LaunchAgents/$agentName
62 sudo launchctl load -w /Library/LaunchDaemons/$daemonName
70 ] ++ lib.optionals unfreeFonts [
71 xorg.fontbhlucidatypewriter100dpi
72 xorg.fontbhlucidatypewriter75dpi
75 fontsConf = makeFontsConf {
76 fontDirectories = fontDirs ++ [
81 fonts = import ./system-fonts.nix {
82 inherit stdenv xorg fontDirs;
84 # any X related programs expected to be available via $PATH
87 quartz-wm xterm fontconfig
90 bdftopcf fontutil iceauth libXpm lndir luit makedepend mkfontdir
91 mkfontscale sessreg setxkbmap smproxy twm x11perf xauth xbacklight xclock
92 xcmsdb xcursorgen xdm xdpyinfo xdriinfo xev xeyes xfs xgamma xhost
93 xinput xkbcomp xkbevd xkbutils xkill xlsatoms xlsclients xmessage xmodmap
94 xpr xprop xrandr xrdb xrefresh xset xsetroot xvinfo xwd xwininfo xwud
96 in stdenv.mkDerivation {
98 version = lib.getVersion xorg.xorgserver;
100 nativeBuildInputs = [ makeWrapper ];
102 unpackPhase = "sourceRoot=.";
107 cp -rT ${xorg.xinit} $out
109 cp -rT ${xorg.xorgserver} $out
112 cp ${installer} $out/bin/xquartz-install
114 rm -rf $out/LaunchAgents $out/LaunchDaemons
116 fontsConfPath=$out/etc/X11/fonts.conf
117 cp ${fontsConf} $fontsConfPath
119 substituteInPlace $out/bin/startx \
120 --replace "bindir=${xorg.xinit}/bin" "bindir=$out/bin" \
121 --replace 'defaultserver=${xorg.xorgserver}/bin/X' "defaultserver=$out/bin/Xquartz" \
122 --replace "${xorg.xinit}" "$out" \
123 --replace "${xorg.xorgserver}" "$out" \
124 --replace "eval xinit" "eval $out/bin/xinit" \
125 --replace "sysclientrc=/etc/X11/xinit/xinitrc" "sysclientrc=$out/etc/X11/xinit/xinitrc"
127 wrapProgram $out/bin/Xquartz \
128 --set XQUARTZ_APP $out/Applications/XQuartz.app
130 defaultStartX="$out/bin/startx -- $out/bin/Xquartz"
132 ${xcbuild}/bin/PlistBuddy $out/Applications/XQuartz.app/Contents/Info.plist <<EOF
133 Add :LSEnvironment dictionary
134 Add :LSEnvironment:XQUARTZ_DEFAULT_CLIENT string "${xterm}/bin/xterm"
135 Add :LSEnvironment:XQUARTZ_DEFAULT_SHELL string "${shell}"
136 Add :LSEnvironment:XQUARTZ_DEFAULT_STARTX string "$defaultStartX"
137 Add :LSEnvironment:FONTCONFIG_FILE string "$fontsConfPath"
141 substituteInPlace $out/etc/X11/xinit/xinitrc \
142 --replace ${xorg.xinit} $out \
143 --replace xmodmap ${xorg.xmodmap}/bin/xmodmap \
144 --replace xrdb ${xorg.xrdb}/bin/xrdb
146 mkdir -p $out/etc/X11/xinit/xinitrc.d
148 cp ${./10-fontdir.sh} $out/etc/X11/xinit/xinitrc.d/10-fontdir.sh
149 substituteInPlace $out/etc/X11/xinit/xinitrc.d/10-fontdir.sh \
150 --subst-var-by "SYSTEM_FONTS" "${fonts}/share/X11-fonts/" \
151 --subst-var-by "XSET" "${xorg.xset}/bin/xset"
153 cp ${./98-user.sh} $out/etc/X11/xinit/xinitrc.d/98-user.sh
155 cat > $out/etc/X11/xinit/xinitrc.d/99-quartz-wm.sh <<EOF
156 exec ${quartz-wm}/bin/quartz-wm
158 chmod +x $out/etc/X11/xinit/xinitrc.d/99-quartz-wm.sh
160 substituteInPlace $out/etc/X11/xinit/privileged_startx.d/20-font_cache \
161 --replace ${xorg.xinit} $out
163 cp ${./font_cache} $out/bin/font_cache
164 substituteInPlace $out/bin/font_cache \
165 --subst-var-by "shell" "${stdenv.shell}" \
166 --subst-var-by "PATH" "$out/bin" \
167 --subst-var-by "ENCODINGSDIR" "${xorg.encodings}/share/fonts/X11/encodings" \
168 --subst-var-by "MKFONTDIR" "${xorg.mkfontdir}/bin/mkfontdir" \
169 --subst-var-by "MKFONTSCALE" "${xorg.mkfontscale}/bin/mkfontscale" \
170 --subst-var-by "FC_CACHE" "${fontconfig.bin}/bin/fc-cache" \
171 --subst-var-by "FONTCONFIG_FILE" "$fontsConfPath"
179 platforms = platforms.darwin;
180 maintainers = with maintainers; [ ];
181 license = licenses.mit;