lol
1{ lib, stdenv, fetchurl
2, autoPatchelfHook, makeDesktopItem, copyDesktopItems, makeWrapper, gnugrep, asar
3, electron, python3, alsa-lib, gtk3, libdbusmenu, libxshmfence, mesa, nss
4}:
5
6stdenv.mkDerivation rec {
7 pname = "whalebird";
8 version = "5.0.7";
9
10 src = let
11 downloads = "https://github.com/h3poteto/whalebird-desktop/releases/download/v${version}";
12 in
13 if stdenv.system == "x86_64-linux" then
14 fetchurl {
15 url = downloads + "/Whalebird-${version}-linux-x64.tar.bz2";
16 hash = "sha256-eufP038REwF2VwAxxI8R0S3fE8oJ+SX/CES5ozuut2w=";
17 }
18 else if stdenv.system == "aarch64-linux" then
19 fetchurl {
20 url = downloads + "/Whalebird-${version}-linux-arm64.tar.bz2";
21 hash = "sha256-U0xVTUUm6wsRxYc1w4vfNtVE6o8dNzXTSi+IX4mgDEE=";
22 }
23 else
24 throw "Whalebird is not supported for ${stdenv.system}";
25
26 nativeBuildInputs = [
27 autoPatchelfHook
28 makeWrapper
29 copyDesktopItems
30 gnugrep
31 asar
32 ];
33
34 buildInputs = [ alsa-lib gtk3 libdbusmenu libxshmfence mesa nss ];
35
36 desktopItems = [
37 (makeDesktopItem {
38 desktopName = "Whalebird";
39 comment = meta.description;
40 categories = [ "Network" ];
41 exec = "whalebird";
42 icon = "whalebird";
43 name = "whalebird";
44 })
45 ];
46
47 unpackPhase = ''
48 mkdir -p opt
49 tar -xf ${src} -C opt
50 # remove the version/target suffix from the untar'd directory
51 mv opt/Whalebird-* opt/Whalebird
52 '';
53
54 buildPhase = ''
55 runHook preBuild
56
57 # Necessary steps to find the tray icon
58 # For aarch64-linux, we need to overwrite this symlink first as it points to
59 # /usr/bin/python3
60 if [ "${stdenv.system}" = "aarch64-linux" ]
61 then ln -sf ${python3}/bin/python3 \
62 opt/Whalebird/resources/app.asar.unpacked/node_modules/better-sqlite3/build/node_gyp_bins/python3
63 fi
64 asar extract opt/Whalebird/resources/app.asar "$TMP/work"
65 substituteInPlace "$TMP/work/dist/electron/main.js" \
66 --replace "$(grep -oE '.{2},"tray_icon.png"' "$TMP/work/dist/electron/main.js")" \
67 "\"$out/opt/Whalebird/resources/build/icons/tray_icon.png\""
68 asar pack --unpack='{*.node,*.ftz,rect-overlay}' "$TMP/work" opt/Whalebird/resources/app.asar
69
70 runHook postBuild
71 '';
72
73 installPhase = ''
74 runHook preInstall
75
76 mkdir $out
77 mv opt $out
78
79 # install icons
80 for icon in $out/opt/Whalebird/resources/build/icons/*.png; do
81 mkdir -p "$out/share/icons/hicolor/$(basename $icon .png)/apps"
82 ln -s "$icon" "$out/share/icons/hicolor/$(basename $icon .png)/apps/whalebird.png"
83 done
84
85 makeWrapper ${electron}/bin/electron $out/bin/whalebird \
86 --add-flags $out/opt/Whalebird/resources/app.asar \
87 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
88
89 runHook postInstall
90 '';
91
92 meta = with lib; {
93 description = "Electron based Mastodon, Pleroma and Misskey client for Windows, Mac and Linux";
94 homepage = "https://whalebird.social";
95 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
96 license = licenses.gpl3Only;
97 maintainers = with maintainers; [ wolfangaukang colinsane weathercold ];
98 platforms = [ "x86_64-linux" "aarch64-linux" ];
99 };
100}