{
  lib,
  stdenv,
  makeWrapper,
  jdk8,
  libGL,
  xorg,
  alsa-lib,
}:

stdenv.mkDerivation rec {
  pname = "tunerstudio";
  version = "3.3.01";

  src = builtins.fetchTarball {
    url = "http://tunerstudio.com/downloads2/TunerStudioMS_v${version}.tar.gz";
    sha256 = "sha256:16xq4ylnlfjacpi9009l6l92zhy1c9sbxvmbkykilaipnflrhwsn";
  };

  nativeBuildInputs = [
    makeWrapper
  ];

  buildInputs = [
    jdk8
    libGL
    xorg.libX11
    alsa-lib
  ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/share/tunerstudio
    mkdir -p $out/bin

    cp -r . $out/share/tunerstudio/

    makeWrapper ${jdk8}/bin/java $out/bin/tunerstudio \
      --run "cd $out/share/tunerstudio" \
      --add-flags "-Dcom.ibm.crypto.provider.DoRSATypeChecking=false" \
      --add-flags "-Djava.library.path=lib/alternateLinuxDrivers/x86_64-linux:lib" \
      --add-flags "-Dfile.encoding=UTF8" \
      --add-flags "-cp '.:lib:plugins'" \
      --add-flags "-jar $out/share/tunerstudio/TunerStudioMS.jar" \
      --prefix LD_LIBRARY_PATH : "${
        lib.makeLibraryPath [
          libGL
          xorg.libX11
          alsa-lib
        ]
      }"

    runHook postInstall
  '';

  meta = {
    description = "MSTune / TunerStudio MS - ECU Tuning Software";
    homepage = "https://www.tunerstudio.com/";
    license = lib.licenses.unfree;
    platforms = lib.platforms.linux;
  };
}
