diff --git a/pkgs/by-name/je/jetbrains-toolbox/package.nix b/pkgs/by-name/je/jetbrains-toolbox/package.nix index 02041695eb18..d52400feecd1 100644 --- a/pkgs/by-name/je/jetbrains-toolbox/package.nix +++ b/pkgs/by-name/je/jetbrains-toolbox/package.nix @@ -1,88 +1,114 @@ { - stdenv, lib, - fetchzip, - copyDesktopItems, - makeWrapper, - runCommand, + stdenv, appimageTools, + fetchzip, + fetchurl, + makeWrapper, icu, - genericUpdater, - writeShellScript, + undmg, }: + let pname = "jetbrains-toolbox"; - version = "2.5.1.34629"; + version = "2.6.1.40902"; - src = fetchzip { - url = "https://download.jetbrains.com/toolbox/jetbrains-toolbox-${version}.tar.gz"; - hash = "sha256-YaMlvgktoa738grHarJX2Uh5PZ7qHuASyJBcUhMssEI="; - stripRoot = false; - }; + updateScript = ./update.sh; - appimageContents = - runCommand "${pname}-extracted" - { - nativeBuildInputs = [ appimageTools.appimage-exec ]; - } - '' - appimage-exec.sh -x $out ${src}/jetbrains-toolbox-${version}/jetbrains-toolbox - - # JetBrains ship a broken desktop file. Despite registering a custom - # scheme handler for jetbrains:// URLs, they never mark the command as - # being suitable for passing URLs to. Ergo, the handler never receives - # its payload. This causes various things to break, including login. - # Reported upstream at: https://youtrack.jetbrains.com/issue/TBX-11478/ - sed -Ei '/^Exec=/s/( %U)?$/ %U/' $out/jetbrains-toolbox.desktop - ''; - - appimage = appimageTools.wrapAppImage { - inherit pname version; - src = appimageContents; - }; -in -stdenv.mkDerivation { - inherit - pname - version - src - appimage - ; - - nativeBuildInputs = [ - makeWrapper - copyDesktopItems - ]; - - installPhase = '' - runHook preInstall - - install -Dm644 ${appimageContents}/.DirIcon $out/share/icons/hicolor/scalable/apps/jetbrains-toolbox.svg - makeWrapper ${appimage}/bin/jetbrains-toolbox $out/bin/jetbrains-toolbox \ - --append-flags "--update-failed" \ - --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ icu ]} - - runHook postInstall - ''; - - desktopItems = [ "${appimageContents}/jetbrains-toolbox.desktop" ]; - - # Disabling the tests, this seems to be very difficult to test this app. - doCheck = false; - - passthru.updateScript = genericUpdater { - versionLister = writeShellScript "jetbrains-toolbox-versionLister" '' - curl -Ls 'https://data.services.jetbrains.com/products?code=TBA&release.type=release' \ - | jq -r '.[] | .releases | flatten[] | .build' - ''; - }; - - meta = with lib; { + meta = { description = "Jetbrains Toolbox"; homepage = "https://jetbrains.com/"; - license = licenses.unfree; - maintainers = with maintainers; [ AnatolyPopov ]; - platforms = [ "x86_64-linux" ]; + license = lib.licenses.unfree; + maintainers = with lib.maintainers; [ AnatolyPopov ]; + platforms = [ + "aarch64-linux" + "aarch64-darwin" + "x86_64-linux" + "x86_64-darwin" + ]; mainProgram = "jetbrains-toolbox"; }; -} + + selectSystem = + attrs: + attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + + linux = appimageTools.wrapAppImage rec { + inherit pname version meta; + + source = + let + arch = selectSystem { + x86_64-linux = ""; + aarch64-linux = "-arm64"; + }; + in + fetchzip { + url = "https://download.jetbrains.com/toolbox/jetbrains-toolbox-${version}${arch}.tar.gz"; + hash = selectSystem { + x86_64-linux = "sha256-P4kv6ca6mGtl334HKNkdo9Iib/Cgu3ROrbQKlQqxUj4="; + aarch64-linux = "sha256-mG8GAVPi2I0A13rKhXoXxiRIHK1QOWPv4gZxfm0+DKs="; + }; + }; + + src = appimageTools.extractType2 { + inherit pname version; + src = source + "/jetbrains-toolbox"; + postExtract = '' + patchelf --add-rpath ${lib.makeLibraryPath [ icu ]} $out/jetbrains-toolbox + ''; + }; + + nativeBuildInputs = [ makeWrapper ]; + + extraInstallCommands = '' + install -Dm644 ${src}/jetbrains-toolbox.desktop $out/share/applications/jetbrains-toolbox.desktop + install -Dm644 ${src}/.DirIcon $out/share/icons/hicolor/scalable/apps/jetbrains-toolbox.svg + wrapProgram $out/bin/jetbrains-toolbox \ + --append-flags "--update-failed" + ''; + + passthru = { + src = source; + inherit updateScript; + }; + }; + + darwin = stdenv.mkDerivation (finalAttrs: { + inherit pname version meta; + + src = + let + arch = selectSystem { + x86_64-darwin = ""; + aarch64-darwin = "-arm64"; + }; + in + fetchurl { + url = "https://download.jetbrains.com/toolbox/jetbrains-toolbox-${finalAttrs.version}${arch}.dmg"; + hash = selectSystem { + x86_64-darwin = "sha256-Dw1CqthgvKIlHrcQIoOpYbAG5c6uvq/UgzaO4n25YJY="; + aarch64-darwin = "sha256-b/z8Pq8h6n34junSMyxRS3Y/TQ3tu05Bh77xlvMvEtI="; + }; + }; + + nativeBuildInputs = [ undmg ]; + + sourceRoot = "JetBrains Toolbox.app"; + + installPhase = '' + runHook preInstall + + mkdir -p $out/Applications $out/bin + cp -r . $out/Applications/"JetBrains Toolbox.app" + ln -s $out/Applications/"JetBrains Toolbox.app"/Contents/MacOS/jetbrains-toolbox $out/bin/jetbrains-toolbox + + runHook postInstall + ''; + + passthru = { + inherit updateScript; + }; + }); +in +if stdenv.hostPlatform.isDarwin then darwin else linux diff --git a/pkgs/by-name/je/jetbrains-toolbox/update.sh b/pkgs/by-name/je/jetbrains-toolbox/update.sh new file mode 100755 index 000000000000..a6b1d812c9d9 --- /dev/null +++ b/pkgs/by-name/je/jetbrains-toolbox/update.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash nix curl coreutils jq common-updater-scripts + +set -eou pipefail + +latestVersion=$(curl -Ls 'https://data.services.jetbrains.com/products?code=TBA&release.type=release' | jq -r '.[0].releases | flatten | .[0].build') +currentVersion=$(nix-instantiate --eval -E "with import ./. {}; jetbrains-toolbox.version or (lib.getVersion jetbrains-toolbox)" | tr -d '"') + +echo "latest version: $latestVersion" +echo "current version: $currentVersion" + +if [[ "$latestVersion" == "$currentVersion" ]]; then + echo "package is up-to-date" + exit 0 +fi + +linux_systems=( + "x86_64-linux:" + "aarch64-linux:-arm64" +) + +for entry in "${linux_systems[@]}"; do + arch="${entry%%:*}" + suffix="${entry#*:}" + prefetch=$(nix-prefetch-url --unpack "https://download.jetbrains.com/toolbox/jetbrains-toolbox-$latestVersion$suffix.tar.gz") + hash=$(nix hash convert --hash-algo sha256 --to sri $prefetch) + update-source-version jetbrains-toolbox $latestVersion $hash --system=$arch --ignore-same-version +done + +darwin_systems=( + "x86_64-darwin:" + "aarch64-darwin:-arm64" +) + +for entry in "${darwin_systems[@]}"; do + arch="${entry%%:*}" + suffix="${entry#*:}" + prefetch=$(nix-prefetch-url "https://download.jetbrains.com/toolbox/jetbrains-toolbox-$latestVersion$suffix.dmg") + hash=$(nix hash convert --hash-algo sha256 --to sri $prefetch) + update-source-version jetbrains-toolbox $latestVersion $hash --system=$arch --ignore-same-version +done