{ config, pkgs, lib, ... }: {
  nixpkgs.overlays = [
    (final: prev: {
      st = prev.st.override {
        conf = builtins.readFile (pkgs.replaceVars ./dwm/st-config.def.h {});
      };
    })
  ];
  services.xserver.windowManager.dwm = {
    enable = true;
    package = let
      launch_emacs = pkgs.writeScript "emacsclient-or-start" ''
        #!${pkgs.bash}/bin/bash
        emacsclient --create-frame --alternate-editor=""
      '';
    in pkgs.dwm.override {
      conf = pkgs.replaceVars ./dwm/config.h {
        dmenucmd="${pkgs.dmenu}/bin/dmenu_run";
        termcmd="${pkgs.st}/bin/st";
        editcmd="${launch_emacs}";
        playcmd=pkgs.writeScript "playerctl-play-pause" ''
          #!${pkgs.bash}/bin/bash
          ${pkgs.playerctl}/bin/playerctl play-pause
        '';
        scrncmd=pkgs.writeScript "screenshot-region" ''
          #!${pkgs.bash}/bin/bash
          ${pkgs.maim}/bin/maim -o -s | ${pkgs.xclip}/bin/xclip -sel clip -t image/png
        '';
      };
      patches = [
        ./dwm/fullscreen.patch
      ];
    };
  };
  services.xserver.enable = true;
  # services.xserver.xrandrHeads should work, but alas
  services.xserver.displayManager.setupCommands = ''
    ${pkgs.xorg.xrandr}/bin/xrandr --output DP-4 --auto --output DP-2 --auto --right-of DP-4 --primary --output HDMI-0 --auto --right-of DP-2;
  '';
  services.xserver.displayManager.lightdm = {
	  enable = true;
    background = "#000000";
  };
  services.xserver.config = lib.mkAfter ''
Section "InputClass"
        Identifier "joystick catchall"
        MatchIsJoystick "on"
        MatchDevicePath "/dev/input/event*"
        Driver "joystick"
        Option "StartKeysEnabled" "False"
        Option "StartMouseEnabled" "False"
EndSection
  '';
  environment.sessionVariables = {
    GTK_THEME="Adwaita-dark";
  };

  environment.systemPackages = with pkgs; [
    dmenu
    xclip
    pwvucontrol
    st
  ];
}
