From ea2a723c00f7c3f083042aa45b967655a74ab6a3 Mon Sep 17 00:00:00 2001
From: Sebastian Neubauer <Sebastian.Neubauer@amd.com>
Date: Wed, 8 Sep 2021 16:14:29 +0200
Subject: [PATCH] rocm-thunk: add update script

---
 pkgs/development/libraries/rocm-thunk/default.nix | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pkgs/development/libraries/rocm-thunk/default.nix b/pkgs/development/libraries/rocm-thunk/default.nix
index 432688e1bfb5..4d641f873021 100644
--- a/pkgs/development/libraries/rocm-thunk/default.nix
+++ b/pkgs/development/libraries/rocm-thunk/default.nix
@@ -1,5 +1,6 @@
 { lib, stdenv
 , fetchFromGitHub
+, writeScript
 , cmake
 , pkg-config
 , numactl
@@ -28,6 +29,13 @@ stdenv.mkDerivation rec {
     cp -r $src/include $out
   '';
 
+  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/RadeonOpenCompute/ROCT-Thunk-Interface/tags" | jq '.[].name | split("-") | .[1] | select( . != null )' --raw-output | sort -n | tail -1)"
+    update-source-version rocm-thunk "$version"
+  '';
+
   meta = with lib; {
     description = "Radeon open compute thunk interface";
     homepage = "https://github.com/RadeonOpenCompute/ROCT-Thunk-Interface";