{
  fetchFromGitHub,
  stdenv,
  cmake,
  obs-studio,
  opencv,
  onnx-runtime,
}:
stdenv.mkDerivation {
  pname = "obs-backgroundremoval";
  version = "0.5.14";

  src = fetchFromGitHub {
    owner = "royshil";
    repo = "obs-backgroundremoval";
    rev = "a42c888ed578e026b31813fc5103ebfe48befebb";
    sha256 = "wCuvWn8BCzi/OrQnfXeUO2oJbw/wH1SUz1d2E/m8u9c=";
  };

  # cmakeFlags = [ "-DGIT_TAG=v${version}" ];
  cmakeFlags = [
    "-DUSE_SYSTEM_ONNXRUNTIME=ON"
    "-DUSE_SYSTEM_OPENCV=ON"
  ];
  patches = [ ./cmake_fix_opencv_link.patch ];

  installPhase = ''
    mkdir -p $out/lib/obs-plugins
    cp rundir/Release/obs-plugins/64bit/obs-backgroundremoval.so $out/lib/obs-plugins/

    mkdir -p $out/share/obs/obs-plugins/obs-backgroundremoval
    cp -r rundir/Release/data/obs-plugins/obs-backgroundremoval/data/* $out/share/obs/obs-plugins/obs-backgroundremoval/
  '';

  nativeBuildInputs = [ cmake ];
  buildInputs = [
    opencv
    onnx-runtime
    obs-studio
  ];
}