Commit 2268cf93 authored by Kyle Carberry's avatar Kyle Carberry
Browse files

coder: add support for mainline channel

Coder releases with the latest tag for a stable release,
and an untagged latest release for mainline.

This change enables the update script to update both
release candidates and enables the installation of
both as well!
parent 0c97ced7
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
{ lib
, channel ? "stable"
, fetchurl
, installShellFiles
, makeBinaryWrapper
@@ -9,18 +10,33 @@

let
  inherit (stdenvNoCC.hostPlatform) system;

  channels = {
    stable = {
      version = "2.9.3";
      hash = {
        x86_64-linux = "sha256-6VS21x2egWBV6eJqRCBGG7mEGPIDFtY9GN6Ry4ilC70=";
        x86_64-darwin = "sha256-UBUGjA+jUkT6p9714l8IvDDI/qhWNctVFOvcA2S5kQU=";
        aarch64-linux = "sha256-2QAahqcM2gi3lT+18q2Nm9GNqVsqzX3RajBsTn+KB1c=";
        aarch64-darwin = "sha256-uEH7Y7c9BcU/Q/jwx/inFMvUrgm2dUruID+FJL+rA6Y=";
      };
    };
    mainline = {
      version = "2.10.1";
      hash = {
        x86_64-linux = "sha256-jNPL30e5xvyajlIqivtEpSb3cRhfgFhLFlC+CaLY2IM=";
        x86_64-darwin = "sha256-U1eQaYwnm/mdQoZ8YxK/+s3HboVfMIAtdI7aQnCiDM8=";
        aarch64-linux = "sha256-YtSyKZYG8vdubZUfo2FjEoVwSF82TXzeLJjPpHqgFDk=";
        aarch64-darwin = "sha256-aQSiXK7voP5/mPFIscfTnSc4Ae5/f+WW8MR6ZtuC/eY=";
      };
    };
  };
in
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "coder";
  version = "2.9.1";

  version = channels.${channel}.version;
  src = fetchurl {
    hash = {
      x86_64-linux = "sha256-r4+u/s/dOn2GhyhEROu8i03QY3VA/bIyO/Yj7KSqicY=";
      x86_64-darwin = "sha256-uShCmMvb5OcinqP0CmrlP9QAJkjfG3g1QuHE4JRDOjE=";
      aarch64-linux = "sha256-tvpzfJ95YYfCY5V4iayjAmY5PDw+1uHUhY5F3pv/2Uk=";
      aarch64-darwin = "sha256-sP9HnB2DzAU9IvL3+QPmIFLvRkGkoxSoa68uXGQrNkw=";
    }.${system};
    hash = (channels.${channel}.hash).${system};

    url =
      let
+34 −15
Original line number Diff line number Diff line
@@ -5,12 +5,13 @@ 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//')
# Fetch the latest stable version
LATEST_STABLE_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/coder/coder/releases/latest | jq -r '.tag_name')
LATEST_STABLE_VERSION=$(echo ${LATEST_STABLE_TAG} | sed 's/^v//')

# change version number
sed -e "s/version =.*;/version = \"$LATEST_VERSION\";/g" \
    -i ./default.nix
# Fetch the latest mainline version
LATEST_MAINLINE_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/coder/coder/releases | jq -r '.[0].tag_name')
LATEST_MAINLINE_VERSION=$(echo ${LATEST_MAINLINE_TAG} | sed 's/^v//')

# Define the platforms
declare -A ARCHS=(["x86_64-linux"]="linux_amd64.tar.gz"
@@ -18,15 +19,33 @@ declare -A ARCHS=(["x86_64-linux"]="linux_amd64.tar.gz"
                  ["x86_64-darwin"]="darwin_amd64.zip"
                  ["aarch64-darwin"]="darwin_arm64.zip")

update_version_and_hashes() {
    local version=$1
    local channel=$2

    # Update version number, using '#' as delimiter
    sed -i "/${channel} = {/,/};/{
        s#^\(\s*\)version = .*#\1version = \"$version\";#
    }" ./default.nix

    # 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..."
        local URL="https://github.com/coder/coder/releases/download/v${version}/coder_${version}_${ARCHS[$ARCH]}"
        echo "Fetching hash for $channel/$ARCH..."

        # Fetch the new hash using nix-prefetch-url
  NEW_HASH=$(nix-prefetch-url --type sha256 $URL)
  SRI_HASH=$(nix hash to-sri --type sha256 $NEW_HASH)
        local NEW_HASH=$(nix-prefetch-url --type sha256 $URL)
        local SRI_HASH=$(nix hash to-sri --type sha256 $NEW_HASH)

  # Update the Nix file with the new hash
  sed -i "s|${ARCH} = \"sha256-.*\";|${ARCH} = \"${SRI_HASH}\";|" ./default.nix
        # Update the Nix file with the new hash, using '#' as delimiter and preserving indentation
        sed -i "/${channel} = {/,/};/{
            s#^\(\s*\)${ARCH} = .*#\1${ARCH} = \"${SRI_HASH}\";#
        }" ./default.nix
    done
}

# Update stable channel
update_version_and_hashes $LATEST_STABLE_VERSION "stable"

# Update mainline channel
update_version_and_hashes $LATEST_MAINLINE_VERSION "mainline"