@@ -0,0 +1,140 @@
1+{ stable, version, sha256Hash }:
2+
3+{ mkDerivation, lib, fetchgit, fetchpatch
4+, pkgconfig, pythonPackages, cmake, makeWrapper
5+, qtbase, qtimageformats, gtk3, libappindicator-gtk3, libnotify
6+, dee, ffmpeg, openalSoft, minizip, libopus, alsaLib, libpulseaudio, range-v3
7+}:
8+
9+with lib;
10+
11+mkDerivation rec {
12+ name = "telegram-desktop-${version}";
13+ inherit version;
14+
15+ # Submodules
16+ src = fetchgit {
17+ url = "git://github.com/telegramdesktop/tdesktop";
18+ rev = "v${version}";
19+ sha256 = sha256Hash;
20+ fetchSubmodules = true;
21+ };
22+
23+ # TODO: Not active anymore.
24+ tgaur = fetchgit {
25+ url = "https://aur.archlinux.org/telegram-desktop-systemqt.git";
26+ rev = "1ed27ce40913b9e6e87faf7a2310660c2790b98e";
27+ sha256 = "1i7ipqgisaw54g1nbg2cvpbx89g9gyjjb3sak1486pxsasp1qhyc";
28+ };
29+
30+ patches = [ (if stable
31+ then (fetchpatch {
32+ name = "tdesktop.patch";
33+ url = "https://git.archlinux.org/svntogit/community.git/plain/repos/community-x86_64/tdesktop.patch?h=packages/telegram-desktop&id=f0eefac36f529295f8b065a14b6d5f1a51d7614d";
34+ sha256 = "1a4wap5xnp6zn4913r3zdpy6hvkcfxcy4zzimy7fwzp7iwy20iqa";
35+ })
36+ else (fetchpatch {
37+ name = "tdesktop.patch";
38+ url = "https://git.archlinux.org/svntogit/community.git/plain/repos/community-x86_64/tdesktop.patch?h=packages/telegram-desktop&id=59ca8bd4428cf2fb3f02d7f1e1a5558545a4c075";
39+ sha256 = "0jj2kifzx83f9nhk30csy2373avpyx0ci70a8bc7j2dm3wxym50l";
40+ }))
41+ ];
42+
43+ postPatch = ''
44+ substituteInPlace Telegram/SourceFiles/platform/linux/linux_libs.cpp --replace '"appindicator"' '"${libappindicator-gtk3}/lib/libappindicator3.so"'
45+ substituteInPlace Telegram/SourceFiles/platform/linux/linux_libnotify.cpp --replace '"notify"' '"${libnotify}/lib/libnotify.so"'
46+ '';
47+
48+ nativeBuildInputs = [ pkgconfig pythonPackages.gyp cmake makeWrapper ];
49+
50+ buildInputs = [
51+ qtbase qtimageformats gtk3 libappindicator-gtk3
52+ dee ffmpeg openalSoft minizip libopus alsaLib libpulseaudio range-v3
53+ ];
54+
55+ enableParallelBuilding = true;
56+
57+ GYP_DEFINES = concatStringsSep "," [
58+ "TDESKTOP_DISABLE_CRASH_REPORTS"
59+ "TDESKTOP_DISABLE_AUTOUPDATE"
60+ "TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME"
61+ ];
62+
63+ NIX_CFLAGS_COMPILE = [
64+ "-DTDESKTOP_DISABLE_AUTOUPDATE"
65+ "-DTDESKTOP_DISABLE_CRASH_REPORTS"
66+ "-DTDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME"
67+ "-I${minizip}/include/minizip"
68+ # See Telegram/gyp/qt.gypi
69+ "-I${getDev qtbase}/mkspecs/linux-g++"
70+ ] ++ concatMap (x: [
71+ "-I${getDev qtbase}/include/${x}"
72+ "-I${getDev qtbase}/include/${x}/${qtbase.version}"
73+ "-I${getDev qtbase}/include/${x}/${qtbase.version}/${x}"
74+ "-I${getDev libopus}/include/opus"
75+ "-I${getDev alsaLib}/include/alsa"
76+ "-I${getDev libpulseaudio}/include/pulse"
77+ ]) [ "QtCore" "QtGui" "QtDBus" ];
78+ CPPFLAGS = NIX_CFLAGS_COMPILE;
79+
80+ preConfigure = ''
81+
82+ pushd "Telegram/ThirdParty/libtgvoip"
83+ patch -Np1 -i "${tgaur}/libtgvoip.patch"
84+ popd
85+
86+ sed -i Telegram/gyp/telegram_linux.gypi \
87+ -e 's,/usr,/does-not-exist,g' \
88+ -e 's,appindicator-0.1,appindicator3-0.1,g' \
89+ -e 's,-flto,,g'
90+
91+ sed -i Telegram/gyp/qt.gypi \
92+ -e "s,/usr/include/qt/QtCore/,${qtbase.dev}/include/QtCore/,g" \
93+ -e 's,\d+",\d+" | head -n1,g'
94+ sed -i Telegram/gyp/qt_moc.gypi \
95+ -e "s,/usr/bin/moc,moc,g"
96+ sed -i Telegram/gyp/qt_rcc.gypi \
97+ -e "s,/usr/bin/rcc,rcc,g"
98+
99+ gyp \
100+ -Dbuild_defines=${GYP_DEFINES} \
101+ -Gconfig=Release \
102+ --depth=Telegram/gyp \
103+ --generator-output=../.. \
104+ -Goutput_dir=out \
105+ --format=cmake \
106+ Telegram/gyp/Telegram.gyp
107+
108+ cd out/Release
109+
110+ NUM=$((`wc -l < CMakeLists.txt` - 2))
111+ sed -i "$NUM r $tgaur/CMakeLists.inj" CMakeLists.txt
112+
113+ export ASM=$(type -p gcc)
114+ '';
115+
116+ installPhase = ''
117+ install -Dm755 Telegram $out/bin/telegram-desktop
118+ mkdir -p $out/share/applications $out/share/kde4/services
119+ sed "s,/usr/bin,$out/bin,g" $tgaur/telegram-desktop.desktop > $out/share/applications/telegram-desktop.desktop
120+ sed "s,/usr/bin,$out/bin,g" $tgaur/tg.protocol > $out/share/kde4/services/tg.protocol
121+ for icon_size in 16 32 48 64 128 256 512; do
122+ install -Dm644 "../../../Telegram/Resources/art/icon''${icon_size}.png" "$out/share/icons/hicolor/''${icon_size}x''${icon_size}/apps/telegram-desktop.png"
123+ done
124+
125+ # This is necessary to run Telegram in a pure environment.
126+ wrapProgram $out/bin/telegram-desktop \
127+ --prefix QT_PLUGIN_PATH : "${qtbase}/${qtbase.qtPluginPrefix}" \
128+ --set XDG_RUNTIME_DIR "XDG-RUNTIME-DIR"
129+ sed -i $out/bin/telegram-desktop \
130+ -e "s,'XDG-RUNTIME-DIR',\"\''${XDG_RUNTIME_DIR:-/run/user/\$(id --user)}\","
131+ '';
132+
133+ meta = {
134+ description = "Telegram Desktop messaging app";
135+ license = licenses.gpl3;
136+ platforms = [ "x86_64-linux" "i686-linux" ];
137+ homepage = https://desktop.telegram.org/;
138+ maintainers = with maintainers; [ abbradar garbas primeos ];
139+ };
140+}