about summary refs log tree commit diff
path: root/pkgs/development/tools/tabnine
diff options
context:
space:
mode:
authorBernardo Meurer <bernardo@meurer.org>2022-11-17 12:48:16 -0500
committerBernardo Meurer <bernardo@meurer.org>2022-11-17 13:17:54 -0500
commit6b5448d7e7a23e8da3ecc0952e03ba42d6c625e1 (patch)
tree1546613691b62b08a3a74f5f71f75b129eb42d3a /pkgs/development/tools/tabnine
parentb4a2daa7a4a1ad532ebf9fac42c0101cb4ca8b88 (diff)
tabnine: 4.4.139 -> 4.4.169
Diffstat (limited to 'pkgs/development/tools/tabnine')
-rw-r--r--pkgs/development/tools/tabnine/default.nix33
-rwxr-xr-xpkgs/development/tools/tabnine/fetch-latest.sh29
-rw-r--r--pkgs/development/tools/tabnine/sources.json17
-rwxr-xr-xpkgs/development/tools/tabnine/update.sh50
4 files changed, 77 insertions, 52 deletions
diff --git a/pkgs/development/tools/tabnine/default.nix b/pkgs/development/tools/tabnine/default.nix
index 8e1a1aaea0107..9b2616e7ebd77 100644
--- a/pkgs/development/tools/tabnine/default.nix
+++ b/pkgs/development/tools/tabnine/default.nix
@@ -1,34 +1,18 @@
 { stdenv, lib, fetchurl, unzip }:
 let
-  # You can check the latest version with `curl -sS https://update.tabnine.com/bundles/version`
-  # There's a handy prefetch script in ./fetch-latest.sh
-  version = "4.4.139";
-  supportedPlatforms = {
-    "x86_64-linux" = {
-      name = "x86_64-unknown-linux-musl";
-      hash = "sha256-CXm9WR77SMvv+9w+8QUBNHKPhe4otquLyHAwzd+jbNk=";
-    };
-    "x86_64-darwin" = {
-      name = "x86_64-apple-darwin";
-      hash = "sha256-01lotn9DzgwIj1n9GCUuGmwgtS4DtK+XOl/wduI+QyI=";
-    };
-    "aarch64-darwin" = {
-      name = "aarch64-apple-darwin";
-      hash = "sha256-RQBBsp48Xhxi3WQKsYzSiiSEW8W7UikKAyFf4sJ2JqQ=";
-    };
-  };
+  sources = builtins.fromJSON (builtins.readFile ./sources.json);
   platform =
-    if (builtins.hasAttr stdenv.hostPlatform.system supportedPlatforms) then
-      builtins.getAttr (stdenv.hostPlatform.system) supportedPlatforms
+    if (builtins.hasAttr stdenv.hostPlatform.system sources.platforms) then
+      builtins.getAttr (stdenv.hostPlatform.system) sources.platforms
     else
       throw "Not supported on ${stdenv.hostPlatform.system}";
 in
 stdenv.mkDerivation {
   pname = "tabnine";
-  inherit version;
+  inherit (sources) version;
 
   src = fetchurl {
-    url = "https://update.tabnine.com/bundles/${version}/${platform.name}/TabNine.zip";
+    url = "https://update.tabnine.com/bundles/${sources.version}/${platform.name}/TabNine.zip";
     inherit (platform) hash;
   };
 
@@ -49,13 +33,16 @@ stdenv.mkDerivation {
     runHook postInstall
   '';
 
-  passthru.platform = platform.name;
+  passthru = {
+    platform = platform.name;
+    updateScript = ./update.sh;
+  };
 
   meta = with lib; {
     homepage = "https://tabnine.com";
     description = "Smart Compose for code that uses deep learning to help you write code faster";
     license = licenses.unfree;
-    platforms = attrNames supportedPlatforms;
+    platforms = attrNames sources.platforms;
     maintainers = with maintainers; [ lovesegfault ];
   };
 }
diff --git a/pkgs/development/tools/tabnine/fetch-latest.sh b/pkgs/development/tools/tabnine/fetch-latest.sh
deleted file mode 100755
index 240a55976640b..0000000000000
--- a/pkgs/development/tools/tabnine/fetch-latest.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-function prefetch-sri() {
-    nix-prefetch-url "$1" 2>/dev/null | xargs nix hash to-sri --type sha256
-}
-
-declare -a PLATFORMS=(
-    x86_64-unknown-linux-musl
-    x86_64-apple-darwin
-    aarch64-apple-darwin
-)
-
-LATEST="$(curl -sS https://update.tabnine.com/bundles/version)"
-
-cat <<-EOF
-version = "${LATEST}";
-EOF
-
-for platform in "${PLATFORMS[@]}"; do
-    url="https://update.tabnine.com/bundles/${LATEST}/${platform}/TabNine.zip"
-    sha="$(prefetch-sri "$url")"
-    cat <<-EOF
-name = "${platform}";
-hash = "${sha}";
-
-EOF
-done
diff --git a/pkgs/development/tools/tabnine/sources.json b/pkgs/development/tools/tabnine/sources.json
new file mode 100644
index 0000000000000..e6587ea6bcb13
--- /dev/null
+++ b/pkgs/development/tools/tabnine/sources.json
@@ -0,0 +1,17 @@
+{
+  "version": "4.4.169",
+  "platforms": {
+    "x86_64-linux": {
+      "name": "x86_64-unknown-linux-musl",
+      "hash": "sha256-gLhFSsOcMElm6a4oHM0yLL6ZGtSk+YvAsUTU/UgGwWg="
+    },
+    "aarch64-darwin": {
+      "name": "aarch64-apple-darwin",
+      "hash": "sha256-nEUPSj1BFkZ1VyeA7X3Y0zt6eeD4AKAIcJ51QF24JVA="
+    },
+    "x86_64-darwin": {
+      "name": "x86_64-apple-darwin",
+      "hash": "sha256-GePhGKPvvhYmOSN5NEaqcsFvyuSJi8eTfYTOtufmDiI="
+    }
+  }
+}
diff --git a/pkgs/development/tools/tabnine/update.sh b/pkgs/development/tools/tabnine/update.sh
new file mode 100755
index 0000000000000..5269a027198b9
--- /dev/null
+++ b/pkgs/development/tools/tabnine/update.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl jq git
+#shellcheck shell=bash
+
+set -euo pipefail
+
+SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
+
+function prefetch-sri() {
+    nix-prefetch-url "$1" 2>/dev/null |
+        xargs nix --experimental-features nix-command hash to-sri --type sha256
+}
+
+declare -A platforms=(
+    [x86_64-unknown-linux-musl]="x86_64-linux"
+    [x86_64-apple-darwin]="x86_64-darwin"
+    [aarch64-apple-darwin]="aarch64-darwin"
+)
+
+old_version="$(jq -r '.version' "$SCRIPT_DIR/sources.json")"
+new_version="$(curl -sS https://update.tabnine.com/bundles/version)"
+
+echo "Updating $old_version -> $new_version"
+
+sources_tmp="$(mktemp)"
+trap 'rm -f "$sources_tmp"' EXIT
+
+cat <<EOF >"$sources_tmp"
+{
+  "version": "$new_version",
+  "platforms": {}
+}
+EOF
+
+for platform in "${!platforms[@]}"; do
+    url="https://update.tabnine.com/bundles/${new_version}/${platform}/TabNine.zip"
+    hash="$(prefetch-sri "$url")"
+    nix_platform="${platforms[$platform]}"
+    cat <<<"$(jq --arg nix_platform "$nix_platform" --arg platform "$platform" --arg hash "$hash" '.platforms += {($nix_platform): {name: $platform, hash: $hash}}' "$sources_tmp")" >"$sources_tmp"
+done
+
+cp "$sources_tmp" "$SCRIPT_DIR/sources.json"
+
+if [[ `git status --porcelain "$SCRIPT_DIR/sources.json"` ]]; then
+    git add "$SCRIPT_DIR/sources.json"
+    git commit -m "tabnine: $old_version -> $new_version"
+else
+    echo "No changes made to $SCRIPT_DIR/sources.json, skipping commit"
+fi
+