{ pkgs, ... }: 

let
  inherit (pkgs) writeShellScriptBin symlinkJoin dbus;
  inherit (pkgs) sway-beta mako;
  swayWrapper = writeShellScriptBin "sway" ''
    export XKB_DEFAULT_LAYOUT=de
    cards=( /dev/dri/card* )
    export WLR_DRM_DEVICES="$cards"

    export SDL_VIDEODRIVER=wayland
    # depends on qt5.qtwayland
    export QT_QPA_PLATFORM=wayland
    export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"

    export _JAVA_AWT_VM_NONREPARENTING=1

    exec ${dbus.dbus-launch} --exit-with-session ${sway-beta}/bin/sway
  '';

  swayJoined = symlinkJoin {
    name = "sway-joined";
    paths = [ swayWrapper sway-beta ];
  };
in {
  environment.systemPackages = with pkgs; [
    swayJoined xwayland qt5.qtwayland
    rofi mako
  ];
  environment.loginShellInit = ''
    if [ "$(tty)" = /dev/tty1 ]; then
      exec ${swayJoined}/bin/sway
    fi
  '';

  security.pam.services.swaylock = {};
  hardware.opengl.enable = true;
  fonts.enableDefaultFonts = true;
  programs.dconf.enable = true;

  programs.light.enable = true;
}