diff --git a/pkgs/by-name/hm/hmcl/package.nix b/pkgs/by-name/hm/hmcl/package.nix index 867d97f8c374..58a7124271cb 100644 --- a/pkgs/by-name/hm/hmcl/package.nix +++ b/pkgs/by-name/hm/hmcl/package.nix @@ -26,24 +26,25 @@ vulkan-loader, libpulseaudio, gobject-introspection, + callPackage, }: -let - version = "3.6.12"; - icon = fetchurl { - url = "https://github.com/huanghongxun/HMCL/raw/release-${version}/HMCLauncher/HMCL/HMCL.ico"; - hash = "sha256-+EYL33VAzKHOMp9iXoJaSGZfv+ymDDYIx6i/1o47Dmc="; - }; -in stdenv.mkDerivation (finalAttrs: { pname = "hmcl"; - inherit version; + version = "3.6.12"; src = fetchurl { - url = "https://github.com/huanghongxun/HMCL/releases/download/release-${version}/HMCL-${version}.jar"; + # HMCL has built-in keys, such as the Microsoft OAuth secret and the CurseForge API key. + # See https://github.com/HMCL-dev/HMCL/blob/refs/tags/release-3.6.12/.github/workflows/gradle.yml#L26-L28 + url = "https://github.com/HMCL-dev/HMCL/releases/download/release-${finalAttrs.version}/HMCL-${finalAttrs.version}.jar"; hash = "sha256-ofrG7CVZIODJoHE6owR9P7viBlChamYF5PEpFeeOH4E="; }; + icon = fetchurl { + url = "https://github.com/HMCL-dev/HMCL/raw/release-${finalAttrs.version}/HMCL/src/main/resources/assets/img/icon@8x.png"; + hash = "sha256-1OVq4ujA2ZHboB7zEk7004kYgl9YcoM4qLq154MZMGo="; + }; + dontUnpack = true; dontWrapGApps = true; @@ -71,8 +72,13 @@ stdenv.mkDerivation (finalAttrs: { mkdir -p $out/{bin,lib/hmcl} cp $src $out/lib/hmcl/hmcl.jar - magick ${icon} hmcl.png - install -Dm644 hmcl-1.png $out/share/icons/hicolor/32x32/apps/hmcl.png + + for n in 16 32 48 64 96 128 256 + do + size=$n"x"$n + mkdir -p $out/share/icons/hicolor/$size/apps + magick ${finalAttrs.icon} -resize $size $out/share/icons/hicolor/$size/apps/hmcl.png + done runHook postInstall ''; @@ -113,13 +119,19 @@ stdenv.mkDerivation (finalAttrs: { runHook postFixup ''; - meta = with lib; { + passthru.updateScript = lib.getExe (callPackage ./update.nix { }); + + meta = { homepage = "https://hmcl.huangyuhui.net"; description = "Minecraft Launcher which is multi-functional, cross-platform and popular"; + changelog = "https://docs.hmcl.net/changelog/stable.html"; mainProgram = "hmcl"; - sourceProvenance = with sourceTypes; [ binaryBytecode ]; - license = licenses.gpl3Only; - maintainers = with maintainers; [ daru-san ]; + sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ + daru-san + moraxyc + ]; inherit (hmclJdk.meta) platforms; }; }) diff --git a/pkgs/by-name/hm/hmcl/update.nix b/pkgs/by-name/hm/hmcl/update.nix new file mode 100644 index 000000000000..9b974524f79b --- /dev/null +++ b/pkgs/by-name/hm/hmcl/update.nix @@ -0,0 +1,40 @@ +{ + writeShellApplication, + nix, + nix-update, + curl, + common-updater-scripts, + jq, +}: + +writeShellApplication { + name = "update-hmcl"; + runtimeInputs = [ + curl + jq + nix + common-updater-scripts + nix-update + ]; + + text = '' + # get old info + oldVersion=$(nix-instantiate --eval --strict -A "hmcl.version" | jq -e -r) + + get_latest_release() { + curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \ + -s "https://api.github.com/repos/HMCL-dev/HMCL/releases/latest" | jq -r ".tag_name" + } + + version=$(get_latest_release) + version="''${version#release-}" + + if [[ "$oldVersion" == "$version" ]]; then + echo "Already up to date!" + exit 0 + fi + + nix-update hmcl --version="$version" + update-source-version hmcl --source-key=icon --ignore-same-version + ''; +}