Merge pull request #268592 from ilya-fedin/telegram-darwin

telegram-desktop: build on Darwin

authored by

Nick Cao and committed by
GitHub
af76d9e3 5d08323d

+167 -24
+72 -18
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix
··· 60 , mm-common 61 , rlottie 62 , stdenv 63 , nix-update-script 64 }: 65 ··· 72 73 let 74 tg_owt = callPackage ./tg_owt.nix { 75 abseil-cpp = abseil-cpp.override { 76 cxxStandard = "20"; 77 }; ··· 100 perlPackages.XMLParser 101 ]; 102 }); 103 in 104 stdenv.mkDerivation rec { 105 pname = "telegram-desktop"; ··· 114 }; 115 116 patches = [ 117 # the generated .desktop files contains references to unwrapped tdesktop, breaking scheme handling 118 # and the scheme handler is already registered in the packaged .desktop file, rendering this unnecessary 119 # see https://github.com/NixOS/nixpkgs/issues/218370 ··· 123 }) 124 ]; 125 126 - postPatch = '' 127 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \ 128 --replace '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"' 129 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \ ··· 143 cmake 144 ninja 145 python3 146 gobject-introspection 147 wrapGAppsHook 148 - wrapQtAppsHook 149 extra-cmake-modules 150 ]; 151 152 buildInputs = [ 153 qtbase 154 - qtwayland 155 qtsvg 156 qtimageformats 157 - gtk3 158 boost 159 - fmt 160 - libdbusmenu 161 lz4 162 xxHash 163 ffmpeg 164 openalSoft 165 minizip 166 libopus 167 alsa-lib 168 libpulseaudio 169 pipewire 170 - range-v3 171 - tl-expected 172 hunspell 173 glibmm 174 webkitgtk_6_0 175 jemalloc 176 - rnnoise 177 - protobuf 178 - tg_owt 179 # Transitive dependencies: 180 util-linuxMinimal # Required for libmount thus not nativeBuildInputs. 181 pcre ··· 192 libsysprof-capture 193 libpsl 194 brotli 195 - microsoft-gsl 196 - rlottie 197 - ]; 198 199 cmakeFlags = [ 200 "-Ddisable_autoupdate=ON" ··· 210 export GI_GIR_PATH="$XDG_DATA_DIRS" 211 ''; 212 213 - postFixup = '' 214 # This is necessary to run Telegram in a pure environment. 215 # We also use gappsWrapperArgs from wrapGAppsHook. 216 - wrapProgram $out/bin/telegram-desktop \ 217 "''${gappsWrapperArgs[@]}" \ 218 "''${qtWrapperArgs[@]}" \ 219 --suffix PATH : ${lib.makeBinPath [ xdg-utils ]} 220 ''; 221 222 passthru = { ··· 231 the MTProto secure protocol. 232 ''; 233 license = licenses.gpl3Only; 234 - platforms = platforms.linux; 235 homepage = "https://desktop.telegram.org/"; 236 changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${version}"; 237 maintainers = with maintainers; [ nickcao ]; 238 - mainProgram = "telegram-desktop"; 239 }; 240 }
··· 60 , mm-common 61 , rlottie 62 , stdenv 63 + , darwin 64 + , lld 65 + , libicns 66 , nix-update-script 67 }: 68 ··· 75 76 let 77 tg_owt = callPackage ./tg_owt.nix { 78 + inherit stdenv; 79 abseil-cpp = abseil-cpp.override { 80 cxxStandard = "20"; 81 }; ··· 104 perlPackages.XMLParser 105 ]; 106 }); 107 + mainProgram = if stdenv.isLinux then "telegram-desktop" else "Telegram"; 108 in 109 stdenv.mkDerivation rec { 110 pname = "telegram-desktop"; ··· 119 }; 120 121 patches = [ 122 + ./macos.patch 123 # the generated .desktop files contains references to unwrapped tdesktop, breaking scheme handling 124 # and the scheme handler is already registered in the packaged .desktop file, rendering this unnecessary 125 # see https://github.com/NixOS/nixpkgs/issues/218370 ··· 129 }) 130 ]; 131 132 + postPatch = lib.optionalString stdenv.isLinux '' 133 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \ 134 --replace '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"' 135 substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \ ··· 149 cmake 150 ninja 151 python3 152 + wrapQtAppsHook 153 + ] ++ lib.optionals stdenv.isLinux [ 154 gobject-introspection 155 wrapGAppsHook 156 extra-cmake-modules 157 + ] ++ lib.optionals stdenv.isDarwin [ 158 + lld 159 ]; 160 161 buildInputs = [ 162 qtbase 163 qtsvg 164 qtimageformats 165 boost 166 lz4 167 xxHash 168 ffmpeg 169 openalSoft 170 minizip 171 libopus 172 + range-v3 173 + tl-expected 174 + rnnoise 175 + protobuf 176 + tg_owt 177 + microsoft-gsl 178 + rlottie 179 + ] ++ lib.optionals stdenv.isLinux [ 180 + qtwayland 181 + gtk3 182 + fmt 183 + libdbusmenu 184 alsa-lib 185 libpulseaudio 186 pipewire 187 hunspell 188 glibmm 189 webkitgtk_6_0 190 jemalloc 191 # Transitive dependencies: 192 util-linuxMinimal # Required for libmount thus not nativeBuildInputs. 193 pcre ··· 204 libsysprof-capture 205 libpsl 206 brotli 207 + ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk_11_0.frameworks; [ 208 + Cocoa 209 + CoreFoundation 210 + CoreServices 211 + CoreText 212 + CoreGraphics 213 + CoreMedia 214 + OpenGL 215 + AudioUnit 216 + ApplicationServices 217 + Foundation 218 + AGL 219 + Security 220 + SystemConfiguration 221 + Carbon 222 + AudioToolbox 223 + VideoToolbox 224 + VideoDecodeAcceleration 225 + AVFoundation 226 + CoreAudio 227 + CoreVideo 228 + CoreMediaIO 229 + QuartzCore 230 + AppKit 231 + CoreWLAN 232 + WebKit 233 + IOKit 234 + GSS 235 + MediaPlayer 236 + IOSurface 237 + Metal 238 + NaturalLanguage 239 + libicns 240 + ]); 241 + 242 + env = lib.optionalAttrs stdenv.isDarwin { 243 + NIX_CFLAGS_LINK = "-fuse-ld=lld"; 244 + }; 245 246 cmakeFlags = [ 247 "-Ddisable_autoupdate=ON" ··· 257 export GI_GIR_PATH="$XDG_DATA_DIRS" 258 ''; 259 260 + installPhase = lib.optionalString stdenv.isDarwin '' 261 + mkdir -p $out/Applications 262 + cp -r ${mainProgram}.app $out/Applications 263 + ln -s $out/{Applications/${mainProgram}.app/Contents/MacOS,bin} 264 + ''; 265 + 266 + postFixup = lib.optionalString stdenv.isLinux '' 267 # This is necessary to run Telegram in a pure environment. 268 # We also use gappsWrapperArgs from wrapGAppsHook. 269 + wrapProgram $out/bin/${mainProgram} \ 270 "''${gappsWrapperArgs[@]}" \ 271 "''${qtWrapperArgs[@]}" \ 272 --suffix PATH : ${lib.makeBinPath [ xdg-utils ]} 273 + '' + lib.optionalString stdenv.isDarwin '' 274 + wrapQtApp $out/Applications/${mainProgram}.app/Contents/MacOS/${mainProgram} 275 ''; 276 277 passthru = { ··· 286 the MTProto secure protocol. 287 ''; 288 license = licenses.gpl3Only; 289 homepage = "https://desktop.telegram.org/"; 290 changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${version}"; 291 maintainers = with maintainers; [ nickcao ]; 292 + inherit mainProgram; 293 }; 294 }
+69
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/macos.patch
···
··· 1 + diff --git a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 2 + index ef544803e9..69c61b3139 100644 3 + --- a/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 4 + +++ b/Telegram/SourceFiles/platform/mac/overlay_widget_mac.mm 5 + @@ -97,9 +97,11 @@ void MacOverlayWidgetHelper::updateStyles(bool fullscreen) { 6 + [window setTitleVisibility:NSWindowTitleHidden]; 7 + [window setTitlebarAppearsTransparent:YES]; 8 + [window setStyleMask:[window styleMask] | NSWindowStyleMaskFullSizeContentView]; 9 + +#if 0 10 + if (@available(macOS 12.0, *)) { 11 + _data->topNotchSkip = [[window screen] safeAreaInsets].top; 12 + } 13 + +#endif 14 + } 15 + 16 + void MacOverlayWidgetHelper::refreshButtons(bool fullscreen) { 17 + Submodule Telegram/lib_base contains modified content 18 + 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 19 + index 7ce90d3..dac3c2c 100644 20 + --- a/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm 21 + +++ b/Telegram/lib_base/base/platform/mac/base_battery_saving_mac.mm 22 + @@ -138,6 +138,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) { 23 + _observer = [[LowPowerModeObserver alloc] initWithCallback:std::move(wrapped)]; 24 + 25 + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 26 + +#if 0 27 + if (@available(macOS 12.0, *)) { 28 + [center 29 + addObserver: _observer 30 + @@ -145,6 +146,7 @@ BatterySaving::BatterySaving(Fn<void()> changedCallback) { 31 + name: NSProcessInfoPowerStateDidChangeNotification 32 + object: nil]; 33 + } 34 + +#endif 35 + [center 36 + addObserver: _observer 37 + selector: @selector(powerStateChanged:) 38 + @@ -178,11 +180,13 @@ std::optional<bool> BatterySaving::enabled() const { 39 + return std::nullopt; 40 + } 41 + NSProcessInfo *info = [NSProcessInfo processInfo]; 42 + +#if 0 43 + if (@available(macOS 12.0, *)) { 44 + if ([info isLowPowerModeEnabled]) { 45 + return true; 46 + } 47 + } 48 + +#endif 49 + const auto state = DetectBatteryState(); 50 + if (!state.has || !state.draining) { 51 + return false; 52 + Submodule Telegram/lib_webview contains modified content 53 + diff --git a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 54 + index 738e574..80ff5f0 100644 55 + --- a/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 56 + +++ b/Telegram/lib_webview/webview/platform/mac/webview_mac.mm 57 + @@ -254,10 +254,12 @@ void *Instance::winId() { 58 + } 59 + 60 + void Instance::setOpaqueBg(QColor opaqueBg) { 61 + +#if 0 62 + if (@available(macOS 12.0, *)) { 63 + [_webview setValue: @NO forKey: @"drawsBackground"]; 64 + [_webview setUnderPageBackgroundColor:[NSColor clearColor]]; 65 + } 66 + +#endif 67 + } 68 + 69 + void Instance::resizeToWindow() {
+21 -5
pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/tg_owt.nix
··· 4 , openh264, usrsctp, libevent, libvpx 5 , libX11, libXtst, libXcomposite, libXdamage, libXext, libXrender, libXrandr, libXi 6 , glib, abseil-cpp, pcre, util-linuxMinimal, libselinux, libsepol, pipewire 7 - , mesa, libepoxy, libglvnd, unstableGitUpdater 8 }: 9 10 stdenv.mkDerivation { ··· 24 nativeBuildInputs = [ pkg-config cmake ninja yasm ]; 25 26 buildInputs = [ 27 - libjpeg libopus ffmpeg alsa-lib libpulseaudio protobuf 28 - openh264 usrsctp libevent libvpx 29 libX11 libXtst libXcomposite libXdamage libXext libXrender libXrandr libXi 30 - glib abseil-cpp pcre util-linuxMinimal libselinux libsepol pipewire 31 mesa libepoxy libglvnd 32 - ]; 33 34 patches = [ 35 # GCC 12 Fix
··· 4 , openh264, usrsctp, libevent, libvpx 5 , libX11, libXtst, libXcomposite, libXdamage, libXext, libXrender, libXrandr, libXi 6 , glib, abseil-cpp, pcre, util-linuxMinimal, libselinux, libsepol, pipewire 7 + , mesa, libepoxy, libglvnd, unstableGitUpdater, darwin 8 }: 9 10 stdenv.mkDerivation { ··· 24 nativeBuildInputs = [ pkg-config cmake ninja yasm ]; 25 26 buildInputs = [ 27 + libjpeg libopus ffmpeg protobuf openh264 usrsctp libevent libvpx abseil-cpp 28 + ] ++ lib.optionals stdenv.isLinux [ 29 libX11 libXtst libXcomposite libXdamage libXext libXrender libXrandr libXi 30 + glib pcre util-linuxMinimal libselinux libsepol pipewire alsa-lib libpulseaudio 31 mesa libepoxy libglvnd 32 + ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ 33 + Cocoa 34 + AppKit 35 + IOKit 36 + IOSurface 37 + Foundation 38 + AVFoundation 39 + CoreMedia 40 + VideoToolbox 41 + CoreGraphics 42 + CoreVideo 43 + OpenGL 44 + Metal 45 + MetalKit 46 + CoreFoundation 47 + ApplicationServices 48 + ]); 49 50 patches = [ 51 # GCC 12 Fix
+5 -1
pkgs/top-level/all-packages.nix
··· 35705 35706 taskopen = callPackage ../applications/misc/taskopen { }; 35707 35708 - telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop { }; 35709 35710 telegram-bot-api = callPackage ../servers/telegram-bot-api { }; 35711
··· 35705 35706 taskopen = callPackage ../applications/misc/taskopen { }; 35707 35708 + telegram-desktop = qt6Packages.callPackage ../applications/networking/instant-messengers/telegram/telegram-desktop { 35709 + stdenv = if stdenv.isDarwin 35710 + then overrideSDK stdenv "11.0" 35711 + else stdenv; 35712 + }; 35713 35714 telegram-bot-api = callPackage ../servers/telegram-bot-api { }; 35715