1{
2 lib,
3 stdenvNoCC,
4 fetchzip,
5 fetchFromGitHub,
6 butler,
7 electron,
8 steam-run,
9 makeWrapper,
10 copyDesktopItems,
11 makeDesktopItem,
12}:
13
14let
15 version = "26.1.9";
16
17 itch-setup = fetchzip {
18 url = "https://broth.itch.zone/itch-setup/linux-amd64/1.26.0/itch-setup.zip";
19 stripRoot = false;
20 hash = "sha256-5MP6X33Jfu97o5R1n6Og64Bv4ZMxVM0A8lXeQug+bNA=";
21 };
22
23 sparseCheckout = "/release/images/itch-icons";
24 icons =
25 fetchFromGitHub {
26 owner = "itchio";
27 repo = "itch";
28 rev = "v${version}";
29 hash = "sha256-jugg+hdP0y0OkFhdQuEI9neWDuNf2p3+DQuwxe09Zck=";
30 sparseCheckout = [ sparseCheckout ];
31 }
32 + sparseCheckout;
33in
34stdenvNoCC.mkDerivation (finalAttrs: {
35 pname = "itch";
36 inherit version;
37
38 src = fetchzip {
39 url = "https://broth.itch.zone/itch/linux-amd64/${finalAttrs.version}/archive/default#.zip";
40 stripRoot = false;
41 hash = "sha256-4k6afBgOKGs7rzXAtIBpmuQeeT/Va8/0bZgNYjuJhgI=";
42 };
43
44 nativeBuildInputs = [
45 copyDesktopItems
46 makeWrapper
47 ];
48
49 desktopItems = [
50 (makeDesktopItem {
51 name = "itch";
52 exec = "itch %U";
53 tryExec = "itch";
54 icon = "itch";
55 desktopName = "itch";
56 mimeTypes = [
57 "x-scheme-handler/itchio"
58 "x-scheme-handler/itch"
59 ];
60 comment = "Install and play itch.io games easily";
61 categories = [ "Game" ];
62 })
63 ];
64
65 # As taken from https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=itch-bin
66 installPhase = ''
67 runHook preInstall
68
69 mkdir -p $out/bin $out/share/itch/resources/app
70 cp -r resources/app "$out/share/itch/resources/"
71
72 install -Dm644 LICENSE -t "$out/share/licenses/$pkgname/"
73 install -Dm644 LICENSES.chromium.html -t "$out/share/licenses/$pkgname/"
74
75 for icon in ${icons}/icon*.png
76 do
77 iconsize="''${icon#${icons}/icon}"
78 iconsize="''${iconsize%.png}"
79 icondir="$out/share/icons/hicolor/''${iconsize}x''${iconsize}/apps/"
80 install -Dm644 "$icon" "$icondir/itch.png"
81 done
82
83 runHook postInstall
84 '';
85
86 postFixup = ''
87 makeWrapper ${steam-run}/bin/steam-run $out/bin/itch \
88 --add-flags ${electron}/bin/electron \
89 --add-flags $out/share/itch/resources/app \
90 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
91 --set BROTH_USE_LOCAL butler,itch-setup \
92 --prefix PATH : ${butler}/bin/:${itch-setup}
93 '';
94
95 meta = {
96 description = "Best way to play itch.io games";
97 homepage = "https://github.com/itchio/itch";
98 changelog = "https://github.com/itchio/itch/releases/tag/v${version}-canary";
99 license = lib.licenses.mit;
100 platforms = lib.platforms.linux;
101 sourceProvenance = [ lib.sourceTypes.binaryBytecode ];
102 maintainers = with lib.maintainers; [ pasqui23 ];
103 mainProgram = "itch";
104 };
105})