summaryrefslogtreecommitdiffstats
path: root/pkgs/games/hmcl/default.nix
blob: 3ac7b9a96cdac9755e8edf5aeee50c86b91b2161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ lib
, stdenv
, fetchurl
, makeDesktopItem
, wrapGAppsHook3
, copyDesktopItems
, imagemagick
, jre
, xorg
, libGL
, glfw
, openal
, libglvnd
, alsa-lib
, wayland
, libpulseaudio
, gobject-introspection
}:

let
  version = "3.5.8";
  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;

  src = fetchurl {
    url = "https://github.com/huanghongxun/HMCL/releases/download/release-${version}/HMCL-${version}.jar";
    hash = "sha256-HRTXJhKtRB+pANMAZ9R1kNsSbl/Rr6a8wMhfaPeD/40=";
  };

  dontUnpack = true;

  dontWrapGApps = true;

  desktopItems = [
    (makeDesktopItem {
      name = "HMCL";
      exec = "hmcl";
      icon = "hmcl";
      comment = finalAttrs.meta.description;
      desktopName = "HMCL";
      categories = [ "Game" ];
    })
  ];

  nativeBuildInputs = [
    gobject-introspection
    wrapGAppsHook3
    copyDesktopItems
    imagemagick
  ];

  installPhase = ''
    runHook preInstall

    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

    runHook postInstall
  '';

    fixupPhase =
      let
        libpath = lib.makeLibraryPath ([
          libGL
          glfw
          openal
          libglvnd
        ] ++ lib.optionals stdenv.isLinux [
          xorg.libX11
          xorg.libXxf86vm
          xorg.libXext
          xorg.libXcursor
          xorg.libXrandr
          xorg.libXtst
          libpulseaudio
          wayland
          alsa-lib
        ]);
      in ''
        runHook preFixup

        makeBinaryWrapper ${jre}/bin/java $out/bin/hmcl \
          --add-flags "-jar $out/lib/hmcl/hmcl.jar" \
          --set LD_LIBRARY_PATH ${libpath} \
          ''${gappsWrapperArgs[@]}

        runHook postFixup
      '';

  meta = with lib; {
    homepage = "https://hmcl.huangyuhui.net";
    description = "A Minecraft Launcher which is multi-functional, cross-platform and popular";
    mainProgram = "hmcl";
    sourceProvenance = with sourceTypes; [ binaryBytecode ];
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ daru-san ];
    inherit (jre.meta) platforms;
  };
})