Merge pull request #201658 from lovesegfault/tabnine-auto-update
This commit is contained in:
commit
e2c91016fe
4 changed files with 77 additions and 52 deletions
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
17
pkgs/development/tools/tabnine/sources.json
Normal file
17
pkgs/development/tools/tabnine/sources.json
Normal file
|
@ -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="
|
||||
}
|
||||
}
|
||||
}
|
50
pkgs/development/tools/tabnine/update.sh
Executable file
50
pkgs/development/tools/tabnine/update.sh
Executable file
|
@ -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
|
||||
|
Loading…
Reference in a new issue