about summary refs log tree commit diff
path: root/pkgs/applications/networking/instant-messengers/telegram
diff options
context:
space:
mode:
authorIlya Fedin <fedin-ilja2010@ya.ru>2023-11-20 02:36:39 +0400
committerIlya Fedin <fedin-ilja2010@ya.ru>2023-11-20 02:36:39 +0400
commit533df7ae7523a1e6dd2235a20e65abaa08e3938d (patch)
tree6a233591962689141afc836ce8a7a8c00decbee7 /pkgs/applications/networking/instant-messengers/telegram
parent12a0ade5e458984675b9789a4b260ebabdd2d1ab (diff)
telegram-desktop: build on Darwin
Diffstat (limited to 'pkgs/applications/networking/instant-messengers/telegram')
-rw-r--r--pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix90
-rw-r--r--pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch69
-rw-r--r--pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix26
3 files changed, 162 insertions, 23 deletions
diff --git a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix
index e0d3a4171cacc..83a4f48142f11 100644
--- a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix
+++ b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix
@@ -60,6 +60,9 @@
 , mm-common
 , rlottie
 , stdenv
+, darwin
+, lld
+, libicns
 , nix-update-script
 }:
 
@@ -72,6 +75,7 @@
 
 let
   tg_owt = callPackage ./tg_owt.nix {
+    inherit stdenv;
     abseil-cpp = abseil-cpp.override {
       cxxStandard = "20";
     };
@@ -100,6 +104,7 @@ let
       perlPackages.XMLParser
     ];
   });
+  mainProgram = if stdenv.isLinux then "telegram-desktop" else "Telegram";
 in
 stdenv.mkDerivation rec {
   pname = "telegram-desktop";
@@ -114,6 +119,7 @@ stdenv.mkDerivation rec {
   };
 
   patches = [
+    ./macos.patch
     # the generated .desktop files contains references to unwrapped tdesktop, breaking scheme handling
     # and the scheme handler is already registered in the packaged .desktop file, rendering this unnecessary
     # see https://github.com/NixOS/nixpkgs/issues/218370
@@ -123,7 +129,7 @@ stdenv.mkDerivation rec {
     })
   ];
 
-  postPatch = ''
+  postPatch = lib.optionalString stdenv.isLinux ''
     substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \
       --replace '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"'
     substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \
@@ -143,39 +149,45 @@ stdenv.mkDerivation rec {
     cmake
     ninja
     python3
+    wrapQtAppsHook
+  ] ++ lib.optionals stdenv.isLinux [
     gobject-introspection
     wrapGAppsHook
-    wrapQtAppsHook
     extra-cmake-modules
+  ] ++ lib.optionals stdenv.isDarwin [
+    lld
   ];
 
   buildInputs = [
     qtbase
-    qtwayland
     qtsvg
     qtimageformats
-    gtk3
     boost
-    fmt
-    libdbusmenu
     lz4
     xxHash
     ffmpeg
     openalSoft
     minizip
     libopus
+    range-v3
+    tl-expected
+    rnnoise
+    protobuf
+    tg_owt
+    microsoft-gsl
+    rlottie
+  ] ++ lib.optionals stdenv.isLinux [
+    qtwayland
+    gtk3
+    fmt
+    libdbusmenu
     alsa-lib
     libpulseaudio
     pipewire
-    range-v3
-    tl-expected
     hunspell
     glibmm
     webkitgtk_6_0
     jemalloc
-    rnnoise
-    protobuf
-    tg_owt
     # Transitive dependencies:
     util-linuxMinimal # Required for libmount thus not nativeBuildInputs.
     pcre
@@ -192,9 +204,44 @@ stdenv.mkDerivation rec {
     libsysprof-capture
     libpsl
     brotli
-    microsoft-gsl
-    rlottie
-  ];
+  ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk_11_0.frameworks; [
+    Cocoa
+    CoreFoundation
+    CoreServices
+    CoreText
+    CoreGraphics
+    CoreMedia
+    OpenGL
+    AudioUnit
+    ApplicationServices
+    Foundation
+    AGL
+    Security
+    SystemConfiguration
+    Carbon
+    AudioToolbox
+    VideoToolbox
+    VideoDecodeAcceleration
+    AVFoundation
+    CoreAudio
+    CoreVideo
+    CoreMediaIO
+    QuartzCore
+    AppKit
+    CoreWLAN
+    WebKit
+    IOKit
+    GSS
+    MediaPlayer
+    IOSurface
+    Metal
+    NaturalLanguage
+    libicns
+  ]);
+
+  env = lib.optionalAttrs stdenv.isDarwin {
+    NIX_CFLAGS_LINK = "-fuse-ld=lld";
+  };
 
   cmakeFlags = [
     "-Ddisable_autoupdate=ON"
@@ -210,13 +257,21 @@ stdenv.mkDerivation rec {
     export GI_GIR_PATH="$XDG_DATA_DIRS"
   '';
 
-  postFixup = ''
+  installPhase = lib.optionalString stdenv.isDarwin ''
+    mkdir -p $out/Applications
+    cp -r ${mainProgram}.app $out/Applications
+    ln -s $out/{Applications/${mainProgram}.app/Contents/MacOS,bin}
+  '';
+
+  postFixup = lib.optionalString stdenv.isLinux ''
     # This is necessary to run Telegram in a pure environment.
     # We also use gappsWrapperArgs from wrapGAppsHook.
-    wrapProgram $out/bin/telegram-desktop \
+    wrapProgram $out/bin/${mainProgram} \
       "''${gappsWrapperArgs[@]}" \
       "''${qtWrapperArgs[@]}" \
       --suffix PATH : ${lib.makeBinPath [ xdg-utils ]}
+  '' + lib.optionalString stdenv.isDarwin ''
+    wrapQtApp $out/Applications/${mainProgram}.app/Contents/MacOS/${mainProgram}
   '';
 
   passthru = {
@@ -231,10 +286,9 @@ stdenv.mkDerivation rec {
       the MTProto secure protocol.
     '';
     license = licenses.gpl3Only;
-    platforms = platforms.linux;
     homepage = "https://desktop.telegram.org/";
     changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${version}";
     maintainers = with maintainers; [ nickcao ];
-    mainProgram = "telegram-desktop";
+    inherit mainProgram;
   };
 }
diff --git a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch
new file mode 100644
index 0000000000000..c8424359fdbfd
--- /dev/null
+++ b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch
@@ -0,0 +1,69 @@
+diff --git a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
+index ef544803e9..69c61b3139 100644
+--- a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
++++ b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm
+@@ -97,9 +97,11 @@ void MacOverlayWidgetHelper::updateStyles(bool fullscreen) {
+ 	[window setTitleVisibility:NSWindowTitleHidden];
+ 	[window setTitlebarAppearsTransparent:YES];
+ 	[window setStyleMask:[window styleMask] | NSWindowStyleMaskFullSizeContentView];
++#if 0
+ 	if (@available(macOS 12.0, *)) {
+ 		_data->topNotchSkip = [[window screen] safeAreaInsets].top;
+ 	}
++#endif
+ }
+ 
+ void MacOverlayWidgetHelper::refreshButtons(bool fullscreen) {
+Submodule Telegram/lib_base contains modified content
+diff --git a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm
+index 7ce90d3..dac3c2c 100644
+--- a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm
++++ b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm
+@@ -138,6 +138,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) {
+ 	_observer = [[LowPowerModeObserver alloc] initWithCallback:std::move(wrapped)];
+ 
+ 	NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
++#if 0
+ 	if (@available(macOS 12.0, *)) {
+ 		[center
+ 			addObserver: _observer
+@@ -145,6 +146,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) {
+ 			name: NSProcessInfoPowerStateDidChangeNotification
+ 			object: nil];
+ 	}
++#endif
+ 	[center
+ 		addObserver: _observer
+ 		selector: @selector(powerStateChanged:)
+@@ -178,11 +180,13 @@ std::optional<bool> BatterySaving::enabled() const {
+ 		return std::nullopt;
+ 	}
+ 	NSProcessInfo *info = [NSProcessInfo processInfo];
++#if 0
+ 	if (@available(macOS 12.0, *)) {
+ 		if ([info isLowPowerModeEnabled]) {
+ 			return true;
+ 		}
+ 	}
++#endif
+ 	const auto state = DetectBatteryState();
+ 	if (!state.has || !state.draining) {
+ 		return false;
+Submodule Telegram/lib_webview contains modified content
+diff --git a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
+index 738e574..80ff5f0 100644
+--- a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
++++ b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm
+@@ -254,10 +254,12 @@ void *Instance::winId() {
+ }
+ 
+ void Instance::setOpaqueBg(QColor opaqueBg) {
++#if 0
+ 	if (@available(macOS 12.0, *)) {
+ 		[_webview setValue: @NO forKey: @"drawsBackground"];
+ 		[_webview setUnderPageBackgroundColor:[NSColor clearColor]];
+ 	}
++#endif
+ }
+ 
+ void Instance::resizeToWindow() {
diff --git a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix
index c26bebc8a893f..dddbfb799396c 100644
--- a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix
+++ b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix
@@ -4,7 +4,7 @@
 , openh264, usrsctp, libevent, libvpx
 , libX11, libXtst, libXcomposite, libXdamage, libXext, libXrender, libXrandr, libXi
 , glib, abseil-cpp, pcre, util-linuxMinimal, libselinux, libsepol, pipewire
-, mesa, libepoxy, libglvnd, unstableGitUpdater
+, mesa, libepoxy, libglvnd, unstableGitUpdater, darwin
 }:
 
 stdenv.mkDerivation {
@@ -24,12 +24,28 @@ stdenv.mkDerivation {
   nativeBuildInputs = [ pkg-config cmake ninja yasm ];
 
   buildInputs = [
-    libjpeg libopus ffmpeg alsa-lib libpulseaudio protobuf
-    openh264 usrsctp libevent libvpx
+    libjpeg libopus ffmpeg protobuf openh264 usrsctp libevent libvpx abseil-cpp
+  ] ++ lib.optionals stdenv.isLinux [
     libX11 libXtst libXcomposite libXdamage libXext libXrender libXrandr libXi
-    glib abseil-cpp pcre util-linuxMinimal libselinux libsepol pipewire
+    glib pcre util-linuxMinimal libselinux libsepol pipewire alsa-lib libpulseaudio
     mesa libepoxy libglvnd
-  ];
+  ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
+    Cocoa
+    AppKit
+    IOKit
+    IOSurface
+    Foundation
+    AVFoundation
+    CoreMedia
+    VideoToolbox
+    CoreGraphics
+    CoreVideo
+    OpenGL
+    Metal
+    MetalKit
+    CoreFoundation
+    ApplicationServices
+  ]);
 
   patches = [
     # GCC 12 Fix