anchor.diff:  , fetchpatch
   , file
   , lib
  +, libglvnd
  +, libX11
  +, libxml2
   , lld
   , llvm
   , makeWrapper
  +, numactl
   , perl
   , python
   , rocclr
  
positive.code: , writeText
  }:
  
  stdenv.mkDerivation rec {
    name = "hip";
    version = "4.3.1";
    src = fetchFromGitHub {
      owner = "ROCm-Developer-Tools";
      repo = "HIP";
      rev = "rocm-${version}";
      sha256 = "sha256-dUdP32H0u6kVItS+VUE549vvxkV1mSN84HvyfeK2hEE=";
    };
  
    # FIXME: https://github.com/ROCm-Developer-Tools/HIP/issues/2317
    postPatch = ''
      cp ${rocm-opencl-runtime.src}/amdocl/cl_vk_amd.hpp amdocl/
    '';
  
    nativeBuildInputs = [ cmake python makeWrapper ];
    propagatedBuildInputs = [
      clang
      compiler-rt
      lld
      llvm
      rocclr
      rocm-comgr
      rocm-device-libs
      rocm-runtime
  
negative.code:     export DEVICE_LIB_PATH=${rocm-device-libs}/lib
    '';
  
    cmakeFlags = [
      "-DHIP_PLATFORM=amd"
      "-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}"
      "-DHIP_COMMON_DIR=${hip}"
      "-DROCCLR_PATH=${rocclr}"
    ];
  
    postInstall = ''
      wrapProgram $out/bin/hipcc --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin --prefix PATH : ${lld}/bin --set NIX_CC_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt} 1 --prefix NIX_LDFLAGS ' ' -L${compiler-rt}/lib --prefix NIX_LDFLAGS_FOR_TARGET ' ' -L${compiler-rt}/lib --add-flags "-nogpuinc"
      wrapProgram $out/bin/hipconfig --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin
    '';
  
    passthru.updateScript = writeScript "update.sh" ''
      #!/usr/bin/env nix-shell
      #!nix-shell -i bash -p curl jq common-updater-scripts
      version="$(curl -sL "https://api.github.com/repos/ROCm-Developer-Tools/hipamd/tags" | jq '.[].name | split("-") | .[1] | select( . != null )' --raw-output | sort -n | tail -1)"
      update-source-version hip "$version"
    '';
  
    meta = with lib; {
      description = "C++ Heterogeneous-Compute Interface for Portability";
      homepage = "https://github.com/ROCm-Developer-Tools/hipamd";
      license = licenses.mit;
      maintainers = with maintainers; [ lovesegfault ];
      platforms = platforms.linux;
  