You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.nix 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. { mkDerivation, lib, fetchFromGitHub, fetchsvn, fetchpatch
  2. , pkgconfig, pythonPackages, cmake, wrapGAppsHook, wrapQtAppsHook, gcc9
  3. , qtbase, qtimageformats, gtk3, libappindicator-gtk3, libnotify, xdg_utils
  4. , dee, ffmpeg, openalSoft, minizip, libopus, alsaLib, libpulseaudio, range-v3
  5. }:
  6. with lib;
  7. mkDerivation rec {
  8. pname = "telegram-desktop";
  9. version = "1.8.13";
  10. # Note: Due to our strong dependency on the Arch patches it's probably best
  11. # to also wait for the Arch update (especially if the patches don't apply).
  12. # Telegram-Desktop with submodules
  13. src = fetchFromGitHub {
  14. owner = "telegramdesktop";
  15. repo = "tdesktop";
  16. rev = "v${version}";
  17. sha256 = "19p4cjzk7jyhrd4sd8dq1r1zksff23zyg5rh5vlr3kqd372bffzz";
  18. fetchSubmodules = true;
  19. };
  20. # Arch patches (svn export telegram-desktop/trunk)
  21. archPatches = fetchsvn {
  22. url = "svn://svn.archlinux.org/community/telegram-desktop/trunk";
  23. # svn log svn://svn.archlinux.org/community/telegram-desktop/trunk
  24. rev = "512849";
  25. sha256 = "1hl7znvv6qr4cwpkj8wlplpa63i1lhk2iax7hb4l1s1a4mijx9ls";
  26. };
  27. privateHeadersPatch = fetchpatch {
  28. url = "https://github.com/telegramdesktop/tdesktop/commit/b9d3ba621eb8af638af46c6b3cfd7a8330bf0dd5.patch";
  29. sha256 = "1s5xvcp9dk0jfywssk8xfcsh7bk5xxif8xqnba0413lfx5rgvs5v";
  30. };
  31. # Note: It would be best if someone could get as many patches upstream as
  32. # possible (we currently depend a lot on custom patches...).
  33. patches = [
  34. "${archPatches}/tdesktop.patch"
  35. "${archPatches}/no-gtk2.patch"
  36. "${archPatches}/Revert-Disable-DemiBold-fallback-for-Semibold.patch"
  37. "${archPatches}/tdesktop_lottie_animation_qtdebug.patch"
  38. # "${archPatches}/Revert-Change-some-private-header-includes.patch"
  39. # "${archPatches}/Use-system-wide-font.patch"
  40. ];
  41. postPatch = ''
  42. substituteInPlace Telegram/SourceFiles/platform/linux/linux_libs.cpp \
  43. --replace '"appindicator3"' '"${libappindicator-gtk3}/lib/libappindicator3.so"'
  44. substituteInPlace Telegram/SourceFiles/platform/linux/linux_libnotify.cpp \
  45. --replace '"notify"' '"${libnotify}/lib/libnotify.so"'
  46. '';
  47. # We want to run wrapProgram manually (with additional parameters)
  48. dontWrapGApps = true;
  49. dontWrapQtApps = true;
  50. nativeBuildInputs = [ pkgconfig pythonPackages.gyp cmake wrapGAppsHook wrapQtAppsHook gcc9 ];
  51. buildInputs = [
  52. qtbase qtimageformats gtk3 libappindicator-gtk3
  53. dee ffmpeg openalSoft minizip libopus alsaLib libpulseaudio range-v3
  54. ];
  55. enableParallelBuilding = true;
  56. GYP_DEFINES = concatStringsSep "," [
  57. "TDESKTOP_DISABLE_CRASH_REPORTS"
  58. "TDESKTOP_DISABLE_AUTOUPDATE"
  59. "TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME"
  60. ];
  61. NIX_CFLAGS_COMPILE = [
  62. "-DTDESKTOP_DISABLE_CRASH_REPORTS"
  63. "-DTDESKTOP_DISABLE_AUTOUPDATE"
  64. "-DTDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME"
  65. "-I${minizip}/include/minizip"
  66. # See Telegram/gyp/qt.gypi
  67. "-I${getDev qtbase}/mkspecs/linux-g++"
  68. ] ++ concatMap (x: [
  69. "-I${getDev qtbase}/include/${x}"
  70. "-I${getDev qtbase}/include/${x}/${qtbase.version}"
  71. "-I${getDev qtbase}/include/${x}/${qtbase.version}/${x}"
  72. "-I${getDev libopus}/include/opus"
  73. "-I${getDev alsaLib}/include/alsa"
  74. "-I${getDev libpulseaudio}/include/pulse"
  75. ]) [ "QtCore" "QtGui" "QtDBus" ];
  76. CPPFLAGS = NIX_CFLAGS_COMPILE;
  77. preConfigure = ''
  78. # Patches to revert:
  79. patch -R -Np1 -i "${privateHeadersPatch}"
  80. # Patches to apply:
  81. pushd "Telegram/ThirdParty/libtgvoip"
  82. patch -Np1 -i "${archPatches}/libtgvoip.patch"
  83. popd
  84. # disable static-qt for rlottie
  85. sed "/RLOTTIE_WITH_STATIC_QT/d" -i "Telegram/gyp/lib_rlottie.gyp"
  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. sed -i Telegram/gyp/modules/qt.gypi \
  91. -e "s,/usr/include/qt/QtCore/,${qtbase.dev}/include/QtCore/,g" \
  92. -e 's,\d+",\d+" | head -n1,g'
  93. sed -i Telegram/gyp/modules/qt_moc.gypi \
  94. -e "s,/usr/bin/moc,moc,g"
  95. sed -i Telegram/gyp/modules/qt_rcc.gypi \
  96. -e "s,/usr/bin/rcc,rcc,g"
  97. # Build system assumes x86, but it works fine on non-x86 if we patch this one flag out
  98. sed -i Telegram/ThirdParty/libtgvoip/libtgvoip.gyp \
  99. -e "/-msse2/d"
  100. gyp \
  101. -Dapi_id=17349 \
  102. -Dapi_hash=344583e45741c457fe1862106095a5eb \
  103. -Dbuild_defines=${GYP_DEFINES} \
  104. -Gconfig=Release \
  105. --depth=Telegram/gyp \
  106. --generator-output=../.. \
  107. -Goutput_dir=out \
  108. --format=cmake \
  109. Telegram/gyp/Telegram.gyp
  110. cd out/Release
  111. NUM=$((`wc -l < CMakeLists.txt` - 2))
  112. sed -i "$NUM r $archPatches/CMakeLists.inj" CMakeLists.txt
  113. export ASM=$(type -p gcc)
  114. '';
  115. cmakeFlags = [ "-UTDESKTOP_OFFICIAL_TARGET" ];
  116. installPhase = ''
  117. install -Dm755 Telegram $out/bin/telegram-desktop
  118. mkdir -p $out/share/applications $out/share/kde4/services
  119. install -m444 "$src/lib/xdg/telegramdesktop.desktop" "$out/share/applications/telegram-desktop.desktop"
  120. sed "s,/usr/bin,$out/bin,g" $archPatches/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.png"
  123. done
  124. '';
  125. postFixup = ''
  126. # This is necessary to run Telegram in a pure environment.
  127. # We also use gappsWrapperArgs from wrapGAppsHook.
  128. wrapProgram $out/bin/telegram-desktop \
  129. "''${gappsWrapperArgs[@]}" \
  130. "''${qtWrapperArgs[@]}" \
  131. --prefix PATH : ${xdg_utils}/bin \
  132. --set XDG_RUNTIME_DIR "XDG-RUNTIME-DIR"
  133. sed -i $out/bin/telegram-desktop \
  134. -e "s,'XDG-RUNTIME-DIR',\"\''${XDG_RUNTIME_DIR:-/run/user/\$(id --user)}\","
  135. '';
  136. meta = {
  137. description = "Telegram Desktop messaging app";
  138. longDescription = ''
  139. Desktop client for the Telegram messenger, based on the Telegram API and
  140. the MTProto secure protocol.
  141. '';
  142. license = licenses.gpl3;
  143. platforms = platforms.linux;
  144. homepage = https://desktop.telegram.org/;
  145. maintainers = with maintainers; [ primeos abbradar ];
  146. };
  147. }