{
  config,
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
  enableCuda ? config.cudaSupport,
  cudaPackages ? { },
}:
let
  effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else stdenv;
in
effectiveStdenv.mkDerivation (finalAttrs: {
  pname = "peakperf";
  version = "1.17";

  src = fetchFromGitHub {
    owner = "Dr-Noob";
    repo = "peakperf";
    rev = "v${finalAttrs.version}";
    hash = "sha256-bP38oo0tHDvzbWHiNwbkQoM7ZQ4nwTimVYfbPh0FUd4=";
  };

  buildInputs =
    [ ]
    ++ lib.optionals enableCuda [
      cudaPackages.cuda_cudart
      cudaPackages.cudatoolkit
      cudaPackages.cuda-samples
    ];

  nativeBuildInputs =
    [
      cmake
    ]
    ++ lib.optionals enableCuda [
      cudaPackages.cuda_nvcc
    ];

  meta = {
    description = "Achieve peak performance on x86 CPUs and NVIDIA GPUs";
    homepage = "https://github.com/Dr-Noob/peakperf";
    license = lib.licenses.gpl2Only;
    mainProgram = "peakperf";
    platforms = lib.platforms.all;
  };
})