@@ -0,0 +1,164 @@
1+{ stdenv, lib, fetchFromGitHub, fetchgit, qtbase, qtimageformats
2+, breakpad, ffmpeg, openalSoft, openssl, zlib, libexif, lzma, libopus
3+, gtk2, glib, cairo, pango, gdk_pixbuf, atk, libappindicator-gtk2
4+, libunity, dee, libdbusmenu-glib, libva
5+
6+, pkgconfig, libxcb, xcbutilwm, xcbutilimage, xcbutilkeysyms
7+, libxkbcommon, libpng, libjpeg, freetype, harfbuzz, pcre16
8+, xproto, libX11, inputproto, sqlite, dbus
9+}:
10+
11+let
12+ system-x86_64 = lib.elem stdenv.system lib.platforms.x86_64;
13+in stdenv.mkDerivation rec {
14+ name = "telegram-desktop-${version}";
15+ version = "0.9.33";
16+ qtVersion = lib.replaceStrings ["."] ["_"] qtbase.version;
17+
18+ src = fetchFromGitHub {
19+ owner = "telegramdesktop";
20+ repo = "tdesktop";
21+ rev = "v${version}";
22+ sha256 = "020vwm7h22951v9zh457d82qy5ifp746vwishkvb16h1vwr1qx4s";
23+ };
24+
25+ tgaur = fetchgit {
26+ url = "https://aur.archlinux.org/telegram-desktop.git";
27+ rev = "df47a864282959b103a08b65844e9088e012fdb3";
28+ sha256 = "1v1dbi8yiaf2hgghniykm5qbnda456xj3zfjnbqysn41f5cn40h4";
29+ };
30+
31+ buildInputs = [
32+ breakpad ffmpeg openalSoft openssl zlib libexif lzma libopus
33+ gtk2 glib libappindicator-gtk2 libunity cairo pango gdk_pixbuf atk
34+ dee libdbusmenu-glib libva
35+ # Qt dependencies
36+ libxcb xcbutilwm xcbutilimage xcbutilkeysyms libxkbcommon
37+ libpng libjpeg freetype harfbuzz pcre16 xproto libX11
38+ inputproto sqlite dbus
39+ ];
40+
41+ nativeBuildInputs = [ pkgconfig ];
42+
43+ enableParallelBuilding = true;
44+
45+ qmakeFlags = [
46+ "CONFIG+=release"
47+ "DEFINES+=TDESKTOP_DISABLE_AUTOUPDATE"
48+ "DEFINES+=TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME"
49+ "INCLUDEPATH+=${gtk2}/include/gtk-2.0"
50+ "INCLUDEPATH+=${glib}/include/glib-2.0"
51+ "INCLUDEPATH+=${glib}/lib/glib-2.0/include"
52+ "INCLUDEPATH+=${cairo}/include/cairo"
53+ "INCLUDEPATH+=${pango}/include/pango-1.0"
54+ "INCLUDEPATH+=${gtk2}/lib/gtk-2.0/include"
55+ "INCLUDEPATH+=${gdk_pixbuf}/include/gdk-pixbuf-2.0"
56+ "INCLUDEPATH+=${atk}/include/atk-1.0"
57+ "INCLUDEPATH+=${libappindicator-gtk2}/include/libappindicator-0.1"
58+ "INCLUDEPATH+=${libunity}/include/unity"
59+ "INCLUDEPATH+=${dee}/include/dee-1.0"
60+ "INCLUDEPATH+=${libdbusmenu-glib}/include/libdbusmenu-glib-0.4"
61+ "INCLUDEPATH+=${breakpad}/include/breakpad"
62+ "LIBS+=-lcrypto"
63+ "LIBS+=-lssl"
64+ "LIBS+=-lz"
65+ "LIBS+=-lgobject-2.0"
66+ "LIBS+=-lxkbcommon"
67+ "LIBS+=-lX11"
68+ "LIBS+=${breakpad}/lib/libbreakpad_client.a"
69+ "LIBS+=./../../../Libraries/QtStatic/qtbase/plugins/platforms/libqxcb.a"
70+ "LIBS+=./../../../Libraries/QtStatic/qtimageformats/plugins/imageformats/libqwebp.a"
71+ ];
72+
73+ qtSrcs = qtbase.srcs ++ [ qtimageformats.src ];
74+ qtPatches = qtbase.patches;
75+
76+ buildCommand = ''
77+ # We don't use nativeBuildInputs to avoid adding system Qt 5 libraries to various paths.
78+ export PATH="${qtbase}/bin:$PATH"
79+
80+ unpackPhase
81+ cd "$sourceRoot"
82+ patchPhase
83+ sed -i 'Telegram/Telegram.pro' \
84+ -e 's/CUSTOM_API_ID//g' \
85+ -e 's,/usr,/does-not-exist,g' \
86+ -e '/LIBS += .*libxkbcommon.a/d' \
87+ -e '/LIBS += .*libz.a/d' \
88+ -e '/LIBS += .*libbreakpad_client.a/d' \
89+ -e 's,-flto ,,g'
90+ echo "Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)" >> Telegram/SourceFiles/stdafx.cpp
91+
92+ ( mkdir -p ../Libraries
93+ cd ../Libraries
94+ for i in $qtSrcs; do
95+ tar -xaf $i
96+ done
97+ mv qt-everywhere-opensource-src-* QtStatic
98+ mv qtbase-opensource-src-* ./QtStatic/qtbase
99+ mv qtimageformats-opensource-src-* ./QtStatic/qtimageformats
100+ cd QtStatic/qtbase
101+ patch -p1 < ../../../$sourceRoot/Telegram/_qtbase_${qtVersion}_patch.diff
102+ cd ..
103+ for i in $qtPatches; do
104+ patch -p1 < $i
105+ done
106+ ${qtbase.postPatch}
107+
108+ export configureFlags="-prefix "../../qt" -release -opensource -confirm-license -system-zlib \
109+ -system-libpng -system-libjpeg -system-freetype -system-harfbuzz -system-pcre -system-xcb \
110+ -system-xkbcommon-x11 -no-opengl -static -nomake examples -nomake tests \
111+ -openssl-linked -dbus-linked -system-sqlite -verbose \
112+ ${lib.optionalString (!system-x86_64) "-no-sse2"} -no-sse3 -no-ssse3 \
113+ -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 -no-mips_dsp -no-mips_dspr2"
114+ export dontAddPrefix=1
115+ export buildFlags="module-qtbase module-qtimageformats"
116+ export installFlags="module-qtbase-install_subtargets module-qtimageformats-install_subtargets"
117+
118+ ( export MAKEFLAGS=-j$NIX_BUILD_CORES
119+ configurePhase
120+ )
121+ buildPhase
122+ installPhase
123+ )
124+
125+ ( mkdir -p Linux/DebugIntermediateStyle
126+ cd Linux/DebugIntermediateStyle
127+ qmake CONFIG+=debug ../../Telegram/MetaStyle.pro
128+ buildPhase
129+ )
130+ ( mkdir -p Linux/DebugIntermediateLang
131+ cd Linux/DebugIntermediateLang
132+ qmake CONFIG+=debug ../../Telegram/MetaLang.pro
133+ buildPhase
134+ )
135+
136+ ( mkdir -p Linux/ReleaseIntermediate
137+ cd Linux/ReleaseIntermediate
138+ qmake $qmakeFlags ../../Telegram/Telegram.pro
139+ pattern="^PRE_TARGETDEPS +="
140+ grep "$pattern" "../../Telegram/Telegram.pro" | sed "s/$pattern//g" | xargs make
141+
142+ qmake $qmakeFlags ../../Telegram/Telegram.pro
143+ buildPhase
144+ )
145+
146+ install -Dm755 Linux/Release/Telegram $out/bin/telegram-desktop
147+ mkdir -p $out/share/applications $out/share/kde4/services
148+ sed "s,/usr/bin,$out/bin,g" $tgaur/telegramdesktop.desktop > $out/share/applications/telegramdesktop.desktop
149+ sed "s,/usr/bin,$out/bin,g" $tgaur/tg.protocol > $out/share/kde4/services/tg.protocol
150+ for icon_size in 16 32 48 64 128 256 512; do
151+ install -Dm644 "Telegram/SourceFiles/art/icon''${icon_size}.png" "$out/share/icons/hicolor/''${icon_size}x''${icon_size}/apps/telegram-desktop.png"
152+ done
153+
154+ fixupPhase
155+ '';
156+
157+ meta = with stdenv.lib; {
158+ description = "Telegram Desktop messaging app";
159+ license = licenses.gpl3;
160+ platforms = platforms.linux;
161+ homepage = "https://desktop.telegram.org/";
162+ maintainers = with maintainers; [ abbradar ];
163+ };
164+}