{
  lib,
  pkgs,
  stdenv,
  fetchFromGitHub,
  dbus,
  qt5,
  qtbase,
  wrapQtAppsHook,
  kpackage,
  kcoreaddons,
  ...
}:
stdenv.mkDerivation rec {
  pname = "kwin-system76-scheduler-integration";
  version = "0.1";

  src = fetchFromGitHub {
    owner = "maxiberta";
    repo = pname;
    rev = version;
    sha256 = "sha256-HX0nK1p97kqt+ZZuECm7Mg9aAXaFDnsJDkbcLUEU+p0=";
  };

  nativeBuildInputs = [
    wrapQtAppsHook
    kpackage
  ];

  buildInputs = [
    dbus
    qt5.qttools.bin
  ];

  dontBuild = true;

  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin
    kpackagetool5 --type=KWin/Script -i . -p $out/share/kwin/scripts

    cat <<EOF > $out/bin/kwin-system76-scheduler-dbus-proxy.sh
    #!${pkgs.bash}/bin/bash
    DBUS_SERVICE="com.system76.Scheduler"
    DBUS_PATH="/com/system76/Scheduler"
    DBUS_INTERFACE="com.system76.Scheduler"
    DBUS_METHOD="SetForegroundProcess"
    echo "starting dbus proxy.."
    echo \''$DBUS_SERVICE \''$DBUS_PATH \''$DBUS_INTERFACE \''$DBUS_METHOD
    ${pkgs.dbus}/bin/dbus-monitor --session "destination=\''$DBUS_SERVICE,path=\''$DBUS_PATH,interface=\''$DBUS_INTERFACE,member=\''$DBUS_METHOD" |
      while true; do
        read method call time sender _ dest serial path interface member
        read type pid
        [ "\''$member" = "member=\''$DBUS_METHOD" ] && ${pkgs.libsForQt5.qt5.qttools.bin}/bin/qdbus --system \''$DBUS_SERVICE \''$DBUS_PATH \''$DBUS_INTERFACE.\''$DBUS_METHOD \''$pid && echo "new foreground process: \''$pid"
      done
    EOF

    chmod +x $out/bin/kwin-system76-scheduler-dbus-proxy.sh

    runHook postInstall
  '';
}
