diff --git a/pkgs/development/tools/coder/default.nix b/pkgs/development/tools/coder/default.nix index 16594ee2e3c3..5557c4db17e5 100644 --- a/pkgs/development/tools/coder/default.nix +++ b/pkgs/development/tools/coder/default.nix @@ -86,4 +86,8 @@ stdenvNoCC.mkDerivation (finalAttrs: { mainProgram = "coder"; maintainers = with lib.maintainers; [ ghuntley urandom ]; }; + + passthru = { + updateScript = ./update.sh; + }; }) diff --git a/pkgs/development/tools/coder/update.sh b/pkgs/development/tools/coder/update.sh new file mode 100755 index 000000000000..a7ce3da93256 --- /dev/null +++ b/pkgs/development/tools/coder/update.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq common-updater-scripts + +set -eu -o pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/coder/coder/releases/latest | jq -r '.tag_name') +LATEST_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//') + +# change version number +sed -e "s/version =.*;/version = \"$LATEST_VERSION\";/g" \ + -i ./default.nix + +# Define the platforms +declare -A ARCHS=(["x86_64-linux"]="linux_amd64.tar.gz" + ["aarch64-linux"]="linux_arm64.tar.gz" + ["x86_64-darwin"]="darwin_amd64.zip" + ["aarch64-darwin"]="darwin_arm64.zip") + +# Update hashes for each architecture +for ARCH in "${!ARCHS[@]}"; do + URL="https://github.com/coder/coder/releases/download/v${LATEST_VERSION}/coder_${LATEST_VERSION}_${ARCHS[$ARCH]}" + echo "Fetching hash for $ARCH..." + + # Fetch the new hash using nix-prefetch-url + NEW_HASH=$(nix-prefetch-url --type sha256 $URL) + + # Update the Nix file with the new hash + sed -i "s|${ARCH} = \"sha256-.*\";|${ARCH} = \"sha256-${NEW_HASH}\";|" ./default.nix +done