anchor.diff:        resolutions = mkOption {
           type = types.listOf types.attrs;
           default = [];
  -        example = [ { x = 1600; y = 1200; } { x = 1024; y = 786; } ];
  +        example = [
  +          { x = 1600; y = 1200; }
  +          { x = 1024; y = 786; }
  +        ];
           description = ''
             The screen resolutions for the X server.  The first element
             is the default resolution.  If this list is empty, the X
  
positive.code:     # 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.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;
  
    # 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;
  
    configFile = pkgs.stdenv.mkDerivation {
      name = "xserver.conf";
  
negative.code: 
      systemd.defaultUnit = mkIf cfg.autorun "graphical.target";
  
      systemd.services.display-manager = {
        description = "X11 Server";
  
        after = [
          "systemd-udev-settle.service"
          "local-fs.target"
          "acpid.service"
          "systemd-logind.service"
        ];
  
        restartIfChanged = false;
  
        environment = {
          XKB_BINDIR = "${xorg.xkbcomp}/bin"; # Needed for the Xkb extension.
          XORG_DRI_DRIVER_PATH = "${pkgs.opengl-dummy.driverSearchPath}/lib/dri"; # !!! Depends on the driver selected at runtime.
          LD_LIBRARY_PATH =
            concatStringsSep ":" (
              [
                "${xorg.libX11}/lib"
                "${xorg.libXext}/lib"
                "${pkgs.opengl-dummy.driverSearchPath}/lib"
              ] ++ concatLists (catAttrs "libPath" cfg.drivers)
            );
        } // cfg.displayManager.job.environment;
  
        preStart = ''
          ${cfg.displayManager.job.preStart}
  
          rm -f /tmp/.X0-lock
        '';
  
        script = "${cfg.displayManager.job.execCmd}";
  
        serviceConfig = {
          Restart = "always";
          RestartSec = "200ms";
        };
      };
  
      services.xserver.displayManager.xserverArgs = [
        "-terminate"
        "-config ${configFile}"
        "-xkbdir" "${cfg.xkbDir}"
      ] ++ optional (cfg.display != null) ":${toString cfg.display}"
        ++ optional (cfg.tty != null) "vt${toString cfg.tty}"
        ++ optionals (cfg.display != null) [
          "-logfile"
          "/var/log/X.${toString cfg.display}.log"
      ] ++ optional (!cfg.enableTCP) "-nolisten tcp";
  
      services.xserver.modules =
        concatLists (catAttrs "modules" cfg.drivers) ++ [
          xorg.xorgserver
          pkgs.xf86-input-evdev
        ];
  
      services.xserver.xkbDir = mkDefault "${pkgs.xkeyboard-config}/etc/X11/xkb";
  
      services.xserver.config = ''
        Section "ServerFlags"
          Option "AllowMouseOpenFail" "on"
          Option "DontZap" "${if cfg.enableCtrlAltBackspace then "off" else "on"}"
          ${cfg.serverFlagsSection}
        EndSection
  
        Section "Module"
          ${cfg.moduleSection}
        EndSection
  
        Section "Monitor"
          Identifier "Monitor[0]"
          ${cfg.monitorSection}
        EndSection
  
        Section "InputClass"
          Identifier "Keyboard catchall"
          MatchIsKeyboard "on"
          Option "XkbRules" "base"
          Option "XkbModel" "${cfg.xkbModel}"
          Option "XkbLayout" "${cfg.layout}"
          Option "XkbOptions" "${cfg.xkbOptions}"
          Option "XkbVariant" "${cfg.xkbVariant}"
        EndSection
  
        # Additional "InputClass" sections
        ${flip concatMapStrings cfg.inputClassSections (inputClassSection: ''
        Section "InputClass"
          ${inputClassSection}
        EndSection
        '')}
  
        Section "ServerLayout"
          Identifier "Layout[all]"
          ${cfg.serverLayoutSection}
          # Reference the Screen sections for each driver.  This will
          # cause the X server to try each in turn.
          ${flip concatMapStrings cfg.drivers (d: ''
            Screen "Screen-${d.name}[0]"
          '')}
        EndSection
  
        ${if cfg.useGlamor then ''
          Section "Module"
            Load "dri2"
            Load "glamoregl"
          EndSection
        '' else ""}
  
        # For each supported driver, add a "Device" and "Screen"
        # section.
        ${flip concatMapStrings cfg.drivers (driver: ''
  
          Section "Device"
            Identifier "Device-${driver.name}[0]"
            Driver "${driver.driverName or driver.name}"
            ${if cfg.useGlamor then ''Option "AccelMethod" "glamor"'' else ""}
            ${driver.extraConfig or ""}
            ${cfg.deviceSection}
            ${xrandrDeviceSection}
          EndSection
  
          Section "Screen"
            Identifier "Screen-${driver.name}[0]"
            Device "Device-${driver.name}[0]"
            ${optionalString (cfg.monitorSection != "") ''
              Monitor "Monitor[0]"
            ''}
  
            ${cfg.screenSection}
  
            ${optionalString (cfg.defaultDepth != 0) ''
              DefaultDepth ${toString cfg.defaultDepth}
            ''}
  
            ${optionalString
              (
                driver.name != "virtualbox"
                && (
                  cfg.resolutions != [ ]
                  || cfg.extraDisplaySettings != ""
                  || cfg.virtualScreen != null
                )
              ) (
                let
                  f = depth: ''
                    SubSection "Display"
                      Depth ${toString depth}
                      ${optionalString (cfg.resolutions != [])
                        "Modes ${concatMapStrings (res: ''"${toString res.x}x${toString res.y}"'') cfg.resolutions}"}
                      ${cfg.extraDisplaySettings}
                      ${optionalString (cfg.virtualScreen != null)
                        "Virtual ${toString cfg.virtualScreen.x} ${toString cfg.virtualScreen.y}"}
                    EndSubSection
                  '';
                  in
                  concatMapStrings f [8 16 24]
              )
            }
          EndSection
  
        '')}
  
        ${xrandrMonitorSections}
      '';
    };
  }
  