{ stdenv, pkgs, fetchurl, lib, unzip, autoPatchelfHook, makeWrapper, ... }:

stdenv.mkDerivation rec {
  pname = "vavra";
  version = "latest";
  src = fetchurl {
    url = "https://dsp56300.com/builds/vavra/beta/DSP56300Emu-1.4.2-Linux_x86_64-Vavra-CLAP.zip";
    sha256 = "sha256-oA+RVI6/CYgOExW/ITgthdJqIEr57qe2byfCHXRqSnU=";
  };
  nativeBuildInputs = [ makeWrapper unzip autoPatchelfHook ];
  buildInputs = with pkgs; [
    freetype
    fontconfig
    alsa-lib
    pipewire
    stdenv.cc.cc.lib
  ];

  unpackPhase = ''
    unzip $src
  '';

  installPhase = ''
    mkdir -p $out/lib/clap
    cp -r usr/local/lib/clap/Vavra.clap $out/lib/clap/
  '';

  postFixup = ''
    patchelf --set-rpath "${lib.makeLibraryPath buildInputs}" $out/lib/clap/Vavra.clap
  '';

  meta = with lib; {
    homepage = "https://dsp56300.wordpress.com/vavra/";
    description = "Vavra";
    platforms = platforms.linux;
  };
}
