{ pkgs, ... }:

let
  inherit (pkgs) stdenv fetchurl jdk wrapGAppsHook makeWrapper gtk3;
in
stdenv.mkDerivation rec {
  pname = "enigma";
  version = "0.23.0";

  src = fetchurl {
    url = "https://maven.fabricmc.net/cuchaz/enigma-swing/${version}/enigma-swing-${version}-all.jar";
    sha256 = "sha256:003y7zjdig5ngjkpzpminp55k3mzv7g2csjp5sfhn26gvm7bnr23";
  };

  buildInputs = [
    gtk3
  ];
  nativeBuildInputs = [
    makeWrapper
    wrapGAppsHook
  ];

  dontUnpack = true;
  buildPhase = "true";
  installPhase = ''
    mkdir -p $out/bin $out/share
    cp $src $out/share/enigma-swing-all.jar
    makeWrapper ${jdk}/bin/java $out/bin/enigma --add-flags "-jar $out/share/enigma-swing-all.jar"
  '';
}