{ pkgs, ... }:

let
  pythonWithPkgs = pkgs.python3.withPackages (
    ps: with ps; [
      ps.pyqt5
      ps.pyqtwebengine
      ps.pyusb
      ps.crcmod
      ps.pyserial
    ]
  );

  src = pkgs.fetchFromGitHub {
    owner = "cedricp";
    repo = "ddt4all";
    rev = "v3.0.4";
    sha256 = "sha256-SswaqV2UabVjuNeMTd7K3Vxa77LZKCb/qkgidkaE0R8=";
  };
in
pkgs.mkShell {
  name = "ddt4all-env";

  buildInputs = [
    pythonWithPkgs
    src
    pkgs.qt5.qtbase
    pkgs.qt5.qttools
    pkgs.git
    pkgs.freetype
    pkgs.libGL
    pkgs.dbus
    pkgs.xorg.libX11
    pkgs.xorg.libXcomposite
    pkgs.xorg.libXdamage
    pkgs.xorg.libXfixes
    pkgs.xorg.libXrender
    pkgs.xorg.libXrandr
    pkgs.xorg.libXtst
    pkgs.glib
    pkgs.expat
    pkgs.fontconfig
  ];

  nativeBuildInputs = [ pkgs.libsForQt5.qt5.wrapQtAppsHook ];

  shellHook = ''
    wrapQtAppsHook
    mkdir -p $HOME/DDT4ALL
    cp -r $src/bin/* $HOME/DDT4ALL

    cd $HOME/DDT4ALL

    python main.py
    exit
  '';
}
