From 318177054ba5200ec0de78ef22f8cd267f30d320 Mon Sep 17 00:00:00 2001 From: squalus Date: Mon, 2 Jan 2023 11:55:52 -0800 Subject: [PATCH] standardnotes: 3.23.69 -> 3.129.0 - add updater script - move source urls and hashes to separate json file - add support for linux-aarch64 --- .../editors/standardnotes/default.nix | 26 +++------ .../editors/standardnotes/src.json | 17 ++++++ .../editors/standardnotes/update.nix | 55 +++++++++++++++++++ 3 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 pkgs/applications/editors/standardnotes/src.json create mode 100644 pkgs/applications/editors/standardnotes/update.nix diff --git a/pkgs/applications/editors/standardnotes/default.nix b/pkgs/applications/editors/standardnotes/default.nix index d4e43b4f71d..461e8dc504d 100644 --- a/pkgs/applications/editors/standardnotes/default.nix +++ b/pkgs/applications/editors/standardnotes/default.nix @@ -1,26 +1,14 @@ -{ lib, stdenv, appimageTools, autoPatchelfHook, desktop-file-utils +{ callPackage, lib, stdenv, appimageTools, autoPatchelfHook, desktop-file-utils , fetchurl, libsecret }: let - version = "3.23.69"; + srcjson = builtins.fromJSON (builtins.readFile ./src.json); + version = srcjson.version; pname = "standardnotes"; name = "${pname}-${version}"; throwSystem = throw "Unsupported system: ${stdenv.hostPlatform.system}"; - plat = { - i686-linux = "i386"; - x86_64-linux = "x86_64"; - }.${stdenv.hostPlatform.system} or throwSystem; - - sha256 = { - i686-linux = "sha256-/A2LjV8ky20bcKgs0ijwldryi5VkyROwz49vWYXYQus="; - x86_64-linux = "sha256-fA9WH9qUtvAHF9hTFRtxQdpz2dpK0joD0zX9VYBo10g="; - }.${stdenv.hostPlatform.system} or throwSystem; - - src = fetchurl { - url = "https://github.com/standardnotes/app/releases/download/%40standardnotes%2Fdesktop%40${version}/standard-notes-${version}-linux-${plat}.AppImage"; - inherit sha256; - }; + src = fetchurl (srcjson.appimage.${stdenv.hostPlatform.system} or throwSystem); appimageContents = appimageTools.extract { inherit name src; @@ -47,6 +35,8 @@ in appimageTools.wrapType2 rec { ln -s ${appimageContents}/usr/share/icons share ''; + passthru.updateScript = callPackage ./update.nix {}; + meta = with lib; { description = "A simple and private notes app"; longDescription = '' @@ -55,8 +45,8 @@ in appimageTools.wrapType2 rec { ''; homepage = "https://standardnotes.org"; license = licenses.agpl3; - maintainers = with maintainers; [ mgregoire chuangzhu ]; + maintainers = with maintainers; [ mgregoire chuangzhu squalus ]; sourceProvenance = [ sourceTypes.binaryNativeCode ]; - platforms = [ "i686-linux" "x86_64-linux" ]; + platforms = builtins.attrNames srcjson.appimage; }; } diff --git a/pkgs/applications/editors/standardnotes/src.json b/pkgs/applications/editors/standardnotes/src.json new file mode 100644 index 00000000000..d8fa27e34a0 --- /dev/null +++ b/pkgs/applications/editors/standardnotes/src.json @@ -0,0 +1,17 @@ +{ + "version": "3.129.0", + "appimage": { + "x86_64-linux": { + "url": "https://github.com/standardnotes/app/releases/download/%40standardnotes/desktop%403.129.0/standard-notes-3.129.0-linux-x86_64.AppImage", + "hash": "sha512-JLO2jX9Us6BjqmTZIkVyxy2pqFM/eFGpwi6vXicMOgDB0UsgEMTK+Ww+9g+vJ1KbFRFmlt187qkdSNcevQPt7w==" + }, + "aarch64-linux": { + "url": "https://github.com/standardnotes/app/releases/download/%40standardnotes/desktop%403.129.0/standard-notes-3.129.0-linux-arm64.AppImage", + "hash": "sha512-LGUSRqMrJ+hVHyi/bjI/NkWRVsmY0Kh/wRY9RNJXm0C3dKQSFV8ca4GeY9+VCuJEecR4LGnWp4agS5jPybPP6w==" + }, + "i686-linux": { + "url": "https://github.com/standardnotes/app/releases/download/%40standardnotes/desktop%403.129.0/standard-notes-3.129.0-linux-i386.AppImage", + "hash": "sha512-XbQ4hn3QJ61hDC12cK95zsUowbyXPYArHZoRDx5trQ30phtQxtz6nV+pL00m4S9kYeEhsAwk1wXlRq9Ylbz2IA==" + } + } +} diff --git a/pkgs/applications/editors/standardnotes/update.nix b/pkgs/applications/editors/standardnotes/update.nix new file mode 100644 index 00000000000..5b8794e9a44 --- /dev/null +++ b/pkgs/applications/editors/standardnotes/update.nix @@ -0,0 +1,55 @@ +{ writeScript +, lib, curl, runtimeShell, jq, coreutils, moreutils, nix, gnused }: + +writeScript "update-standardnotes" '' + #!${runtimeShell} + PATH=${lib.makeBinPath [ jq curl nix coreutils moreutils gnused ]} + + set -euo pipefail + set -x + + tmpDir=$(mktemp -d) + srcJson=pkgs/applications/editors/standardnotes/src.json + jsonPath="$tmpDir"/latest + + oldVersion=$(jq -r .version < "$srcJson") + + curl https://api.github.com/repos/standardnotes/app/releases/latest > "$jsonPath" + + tagName=$(jq -r .tag_name < "$jsonPath") + + if [[ ! "$tagName" =~ "desktop" ]]; then + echo "latest release '$tagName' not a desktop release" + exit 1 + fi + + newVersion=$(jq -r .tag_name < "$jsonPath" | sed s,@standardnotes/desktop@,,g) + + if [[ "$oldVersion" == "$newVersion" ]]; then + echo "version did not change" + exit 0 + fi + + function getDownloadUrl() { + jq -r ".assets[] | select(.name==\"standard-notes-$newVersion-$1.AppImage\") | .browser_download_url" < "$jsonPath" + } + + function setJsonKey() { + jq "$1 = \"$2\"" "$srcJson" | sponge "$srcJson" + } + + function updatePlatform() { + nixPlatform="$1" + upstreamPlatform="$2" + url=$(getDownloadUrl "$upstreamPlatform") + hash=$(nix-prefetch-url "$url" --type sha512) + sriHash=$(nix hash to-sri --type sha512 $hash) + setJsonKey .appimage[\""$nixPlatform"\"].url "$url" + setJsonKey .appimage[\""$nixPlatform"\"].hash "$sriHash" + } + + updatePlatform x86_64-linux linux-x86_64 + updatePlatform aarch64-linux linux-arm64 + updatePlatform i686-linux linux-i386 + setJsonKey .version "$newVersion" +''