hmcl: add updateScript

Moraxyc e5dcb41b c147291a

+43
+3
pkgs/by-name/hm/hmcl/package.nix
··· 26 26 vulkan-loader, 27 27 libpulseaudio, 28 28 gobject-introspection, 29 + callPackage, 29 30 }: 30 31 31 32 stdenv.mkDerivation (finalAttrs: { ··· 112 113 113 114 runHook postFixup 114 115 ''; 116 + 117 + passthru.updateScript = lib.getExe (callPackage ./update.nix { }); 115 118 116 119 meta = { 117 120 homepage = "https://hmcl.huangyuhui.net";
+40
pkgs/by-name/hm/hmcl/update.nix
··· 1 + { 2 + writeShellApplication, 3 + nix, 4 + nix-update, 5 + curl, 6 + common-updater-scripts, 7 + jq, 8 + }: 9 + 10 + writeShellApplication { 11 + name = "update-hmcl"; 12 + runtimeInputs = [ 13 + curl 14 + jq 15 + nix 16 + common-updater-scripts 17 + nix-update 18 + ]; 19 + 20 + text = '' 21 + # get old info 22 + oldVersion=$(nix-instantiate --eval --strict -A "hmcl.version" | jq -e -r) 23 + 24 + get_latest_release() { 25 + curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \ 26 + -s "https://api.github.com/repos/HMCL-dev/HMCL/releases/latest" | jq -r ".tag_name" 27 + } 28 + 29 + version=$(get_latest_release) 30 + version="''${version#release-}" 31 + 32 + if [[ "$oldVersion" == "$version" ]]; then 33 + echo "Already up to date!" 34 + exit 0 35 + fi 36 + 37 + nix-update hmcl --version="$version" 38 + update-source-version hmcl --source-key=icon --ignore-same-version 39 + ''; 40 + }