Unverified Commit 22965458 authored by Weijia Wang's avatar Weijia Wang Committed by GitHub
Browse files

joplin-desktop: add multiarch update script (#375286)

parents f4c3cfc6 c252ce32
Loading
Loading
Loading
Loading
+9 −21
Original line number Diff line number Diff line
@@ -9,29 +9,13 @@

let
  pname = "joplin-desktop";
  version = "3.1.24";
  inherit (releaseData) version;

  inherit (stdenv.hostPlatform) system;
  throwSystem = throw "Unsupported system: ${system}";

  suffix =
    {
      x86_64-linux = ".AppImage";
      x86_64-darwin = ".dmg";
      aarch64-darwin = "-arm64.dmg";
    }
    .${system} or throwSystem;

  src = fetchurl {
    url = "https://github.com/laurent22/joplin/releases/download/v${version}/Joplin-${version}${suffix}";
    sha256 =
      {
        x86_64-linux = "sha256-ImFB4KwJ/vAHtZUbLAdnIRpd+o2ZaXKy9luw/jnPLSE=";
        x86_64-darwin = "sha256-Of6VXX40tCis+ou26LtJKOZm/87P3rsTHtnvSDwF8VY=";
        aarch64-darwin = "sha256-HtHuZQhIkiI8GrhB9nCOTAN1hOs+9POJFRIsRUNikYs=";
      }
      .${system} or throwSystem;
  };
  releaseData = lib.importJSON ./release-data.json;
  src = fetchurl releaseData.${system} or throwSystem;

  appimageContents = appimageTools.extractType2 {
    inherit pname version src;
@@ -77,11 +61,13 @@ let
    extraInstallCommands = ''
      wrapProgram $out/bin/joplin-desktop \
        --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform=wayland --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
      install -Dm644 ${appimageContents}/@joplinapp-desktop.desktop $out/share/applications/joplin.desktop
      install -Dm644 ${appimageContents}/@joplinapp-desktop.png $out/share/pixmaps/joplin.png
      install -Dm644 ${appimageContents}/joplin.desktop $out/share/applications/joplin.desktop
      install -Dm644 ${appimageContents}/joplin.png $out/share/pixmaps/joplin.png
      substituteInPlace $out/share/applications/joplin.desktop \
        --replace-fail 'Exec=AppRun' 'Exec=joplin-desktop'
    '';

    passthru.updateScript = ./update.py;
  };

  darwin = stdenv.mkDerivation {
@@ -108,6 +94,8 @@ let
      cp -R Joplin.app $out/Applications
      runHook postInstall
    '';

    passthru.updateScript = ./update.py;
  };
in
if stdenv.hostPlatform.isDarwin then darwin else linux
+15 −0
Original line number Diff line number Diff line
{
  "version": "3.2.13",
  "x86_64-linux": {
    "url": "https://github.com/laurent22/joplin/releases/download/v3.2.13/Joplin-3.2.13.AppImage",
    "sha256": "06xmm2annf3i8qfi8hclac3lgfssb2f3sx06vgabgsn67i8gid20"
  },
  "x86_64-darwin": {
    "url": "https://github.com/laurent22/joplin/releases/download/v3.2.13/Joplin-3.2.13.dmg",
    "sha256": "1z9lp07z85jf1g2rwzn4q5kssfqqb921lfqgkjkjnz12padf3kpf"
  },
  "aarch64-darwin": {
    "url": "https://github.com/laurent22/joplin/releases/download/v3.2.13/Joplin-3.2.13-arm64.dmg",
    "sha256": "0r7rfka60vrynwxdfk71mbhdwxv2rivxqc2qpzrhmz26h8vksm3h"
  }
}
+32 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p 'python3.withPackages(ps: [ps.requests ps.plumbum])' nix-prefetch
import json
import requests

from pathlib import Path

from plumbum.cmd import nix_prefetch_url

HERE = Path(__file__).parent
SUFFIXES = (
    ("x86_64-linux", ".AppImage"),
    ("x86_64-darwin", ".dmg"),
    ("aarch64-darwin", "-arm64.dmg"),
)

latest = requests.get(
    "https://api.github.com/repos/laurent22/joplin/releases/latest"
).json()
tag = latest["tag_name"]
version = tag[1:]
release = {
    "version": version,
}

for arch, suffix in SUFFIXES:
    url = f"https://github.com/laurent22/joplin/releases/download/v{version}/Joplin-{version}{suffix}"
    release[arch] = {"url": url, "sha256": nix_prefetch_url(url).strip()}

with HERE.joinpath("release-data.json").open("w") as fd:
    json.dump(release, fd, indent=2)
    fd.write("\n")