anchor.diff:      # Sans) than that horror.  But we do need the Adobe fonts for some
       # old non-fontconfig applications.  (Possibly this could be done
       # better using a fontconfig rule.)
  -    [ pkgs.xorg.fontadobe100dpi
  +    [
  +      pkgs.xorg.fontadobe100dpi
         pkgs.xorg.fontadobe75dpi
       ];
   
   
     # Just enumerate all heads without discarding XRandR output information.
  -  xrandrHeads = let
  -    mkHead = num: output: {
  -      name = "multihead${toString num}";
  -      inherit output;
  -    };
  -  in imap mkHead cfg.xrandrHeads;
  -
  -  xrandrDeviceSection = let
  -    monitors = flip map xrandrHeads (h: ''
  -      Option "monitor-${h.output}" "${h.name}"
  -    '');
  -    # First option is indented through the space in the config but any
  -    # subsequent options aren't so we need to apply indentation to
  -    # them here
  -    monitorsIndented = if length monitors > 1
  -      then singleton (head monitors) ++ map (m: "  " + m) (tail monitors)
  -      else monitors;
  -  in concatStrings monitorsIndented;
  +  xrandrHeads =
  +    let
  +      mkHead = num: output: {
  +        name = "multihead${toString num}";
  +        inherit output;
  +      };
  +    in
  +    imap mkHead cfg.xrandrHeads;
  +
  +  xrandrDeviceSection =
  +    let
  +      monitors = flip map xrandrHeads (h: ''
  +        Option "monitor-${h.output}" "${h.name}"
  +      '');
  +      # First option is indented through the space in the config but any
  +      # subsequent options aren't so we need to apply indentation to
  +      # them here
  +      monitorsIndented =
  +        if length monitors > 1 then
  +          singleton (head monitors) ++ map (m: "  " + m) (tail monitors)
  +        else
  +          monitors;
  +    in
  +    concatStrings monitorsIndented;
   
     # Here we chain every monitor from the left to right, so we have:
     # m4 right of m3 right of m2 right of m1   .----.----.----.----.
     # Which will end up in reverse ----------> | m1 | m2 | m3 | m4 |
     #                                          `----^----^----^----'
  -  xrandrMonitorSections = let
  -    mkMonitor = previous: current: singleton {
  -      inherit (current) name;
  -      value = ''
  -        Section "Monitor"
  -          Identifier "${current.name}"
  -          ${optionalString (previous != []) ''
  -          Option "RightOf" "${(head previous).name}"
  -          ''}
  -        EndSection
  -      '';
  -    } ++ previous;
  -    monitors = reverseList (foldl mkMonitor [] xrandrHeads);
  -  in concatMapStrings (getAttr "value") monitors;
  +  xrandrMonitorSections =
  +    let
  +      mkMonitor = previous: current: singleton {
  +        inherit (current) name;
  +        value = ''
  +          Section "Monitor"
  +            Identifier "${current.name}"
  +            ${optionalString (previous != []) ''
  +            Option "RightOf" "${(head previous).name}"
  +            ''}
  +          EndSection
  +        '';
  +      } ++ previous;
  +      monitors = reverseList (foldl mkMonitor [] xrandrHeads);
  +    in
  +    concatMapStrings (getAttr "value") monitors;
   
     configFile = pkgs.stdenv.mkDerivation {
       name = "xserver.conf";
  
positive.code:     hardware.opengl.enable = mkDefault true;
  
      # FIXME: somehow check for unknown driver names.
      services.xserver.drivers = flip concatMap cfg.videoDrivers (name:
        let driver =
          attrByPath [name]
            (if xorg ? ${"xf86video" + name}
             then { modules = [xorg.${"xf86video" + name}]; }
             else null)
            knownVideoDrivers;
        in optional (driver != null) ({ inherit name; driverName = name; } // driver));
  
      assertions =
        [ { assertion = !(config.programs.ssh.startAgent && cfg.startGnuPGAgent);
            message =
              ''
                The OpenSSH agent and GnuPG agent cannot be started both. Please
                choose between ‘programs.ssh.startAgent’ and ‘services.xserver.startGnuPGAgent’.
              '';
          }
          { assertion = config.security.polkit.enable;
            message = "X11 requires Polkit to be enabled (‘security.polkit.enable = true’).";
          }
        ];
  
      environment.etc =
        (optionals cfg.exportConfiguration
          [ { source = "${configFile}";
              target = "X11/xorg.conf";
            }
            # -xkbdir command line option does not seems to be passed to xkbcomp.
            { source = "${cfg.xkbDir}";
              target = "X11/xkb";
            }
          ]);
  
      environment.systemPackages =
        [ xorg.xorgserver
          xorg.xrandr
          pkgs.xrdb
          xorg.setxkbmap
          pkgs.iceauth # required for KDE applications (it's called by dcopserver)
          pkgs.xlsclients
          xorg.xset
          pkgs.xsetroot
          xorg.xinput
          pkgs.xprop
          xorg.xauth
          pkgs.xdg-utils
        ]
        ++ optional (elem "virtualbox" cfg.videoDrivers) xorg.xrefresh;
  
      environment.pathsToLink =
        [ "/etc/xdg" "/share/xdg" "/share/applications" "/share/icons" "/share/pixmaps" ];
  
      # The default max inotify watches is 8192.
      # Nowadays most apps require a good number of inotify watches,
  
negative.code: 
    # Map video driver names to driver packages. FIXME: move into card-specific modules.
    knownVideoDrivers = {
      virtualbox = {
        modules = [
          kernelPackages.virtualboxGuestAdditions
        ];
        driverName = "vboxvideo";
      };
      ati = {
        modules = [
          pkgs.xorg.xf86videoati
          pkgs.xorg.glamoregl
        ];
      };
      intel = {
        modules = with pkgs.xorg; [
          xf86videointel
        ];
        driverName = "intel";
        extraConfig = ''
          Option "DRI" "3"
  