Skip to content

Commit

Permalink
telegram-desktop: make webkitgtk optional
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCao committed Nov 3, 2024
1 parent b6b1e97 commit 2a14d5d
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 268 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, callPackage
, libsForQt5
, yasm
{
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
libsForQt5,
yasm,
}:

let
telegram-desktop = libsForQt5.callPackage ../telegram-desktop { };
version = "1.4.9";
in
(libsForQt5.callPackage ../telegram-desktop/default.nix {
inherit stdenv;

tg_owt = (callPackage ../telegram-desktop/tg_owt.nix {
# tg_owt should use the same compiler
inherit stdenv;
}).overrideAttrs(oldAttrs: {
tg_owt = telegram-desktop.tg_owt.overrideAttrs (oldAttrs: {
version = "0-unstable-2024-06-15";

src = fetchFromGitHub {
Expand All @@ -27,7 +21,7 @@ in
fetchSubmodules = true;
};

patches = (oldAttrs.patches or []) ++ [
patches = (oldAttrs.patches or [ ]) ++ [
(fetchpatch {
url = "https://webrtc.googlesource.com/src/+/e7d10047096880feb5e9846375f2da54aef91202%5E%21/?format=TEXT";
decode = "base64 -d";
Expand All @@ -39,42 +33,44 @@ in

nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ yasm ];
});

withWebKitGTK = false;
}).overrideAttrs {
in
telegram-desktop.override {
pname = "kotatogram-desktop";
version = "${version}-unstable-2024-09-27";
unwrapped = (telegram-desktop.unwrapped.override { inherit tg_owt; }).overrideAttrs {
pname = "kotatogram-desktop-unwrapped";
version = "${version}-unstable-2024-09-27";

src = fetchFromGitHub {
owner = "kotatogram";
repo = "kotatogram-desktop";
rev = "0581eb6219343b3cfcbb81124b372df1039b7568";
hash = "sha256-rvn8GZmHdMkVutLUe/LmUNIawlb9VgU3sYhPwZ2MWsI=";
fetchSubmodules = true;
};
src = fetchFromGitHub {
owner = "kotatogram";
repo = "kotatogram-desktop";
rev = "0581eb6219343b3cfcbb81124b372df1039b7568";
hash = "sha256-rvn8GZmHdMkVutLUe/LmUNIawlb9VgU3sYhPwZ2MWsI=";
fetchSubmodules = true;
};

patches = [
./macos-qt5.patch
(fetchpatch {
url = "https://gitlab.com/mnauw/cppgir/-/commit/c8bb1c6017a6f7f2e47bd10543aea6b3ec69a966.patch";
stripLen = 1;
extraPrefix = "cmake/external/glib/cppgir/";
hash = "sha256-8B4h3BTG8dIlt3+uVgBI569E9eCebcor9uohtsrZpnI=";
})
];
patches = [
./macos-qt5.patch
(fetchpatch {
url = "https://gitlab.com/mnauw/cppgir/-/commit/c8bb1c6017a6f7f2e47bd10543aea6b3ec69a966.patch";
stripLen = 1;
extraPrefix = "cmake/external/glib/cppgir/";
hash = "sha256-8B4h3BTG8dIlt3+uVgBI569E9eCebcor9uohtsrZpnI=";
})
];

meta = with lib; {
description = "Kotatogram – experimental Telegram Desktop fork";
longDescription = ''
Unofficial desktop client for the Telegram messenger, based on Telegram Desktop.
meta = with lib; {
description = "Kotatogram – experimental Telegram Desktop fork";
longDescription = ''
Unofficial desktop client for the Telegram messenger, based on Telegram Desktop.
It contains some useful (or purely cosmetic) features, but they could be unstable. A detailed list is available here: https://kotatogram.github.io/changes
'';
license = licenses.gpl3Only;
platforms = platforms.all;
homepage = "https://kotatogram.github.io";
changelog = "https://github.com/kotatogram/kotatogram-desktop/releases/tag/k${version}";
maintainers = with maintainers; [ ilya-fedin ];
mainProgram = if stdenv.hostPlatform.isLinux then "kotatogram-desktop" else "Kotatogram";
It contains some useful (or purely cosmetic) features, but they could be unstable. A detailed list is available here: https://kotatogram.github.io/changes
'';
license = licenses.gpl3Only;
platforms = platforms.all;
homepage = "https://kotatogram.github.io";
changelog = "https://github.com/kotatogram/kotatogram-desktop/releases/tag/k${version}";
maintainers = with maintainers; [ ilya-fedin ];
mainProgram = if stdenv.hostPlatform.isLinux then "kotatogram-desktop" else "Kotatogram";
};
};
}
Original file line number Diff line number Diff line change
@@ -1,169 +1,73 @@
{ lib
, stdenv
, fetchFromGitHub
, callPackage
, pkg-config
, cmake
, ninja
, clang
, python3
, wrapQtAppsHook
, tg_owt ? callPackage ./tg_owt.nix { inherit stdenv; }
, qtbase
, qtimageformats
, qtsvg
, qtwayland
, kcoreaddons
, lz4
, xxHash
, ffmpeg
, protobuf
, openalSoft
, minizip
, libopus
, alsa-lib
, libpulseaudio
, range-v3
, tl-expected
, hunspell
, gobject-introspection
, jemalloc
, rnnoise
, microsoft-gsl
, boost
, ada
, withWebKitGTK ? true
, wrapGAppsHook3
, glib-networking
, webkitgtk_4_1
, libicns
, apple-sdk_15
, nix-update-script
{
callPackage,
lib,
stdenv,
pname ? "telegram-desktop",
unwrapped ? callPackage ./unwrapped.nix { inherit stdenv; },
qtbase,
qtimageformats,
qtsvg,
qtwayland,
wrapGAppsHook3,
wrapQtAppsHook,
glib-networking,
webkitgtk_4_1,
withWebkit ? true,
}:

# Main reference:
# - This package was originally based on the Arch package but all patches are now upstreamed:
# https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/telegram-desktop
# Other references that could be useful:
# - https://git.alpinelinux.org/aports/tree/testing/telegram-desktop/APKBUILD
# - https://github.com/void-linux/void-packages/blob/master/srcpkgs/telegram-desktop/template

stdenv.mkDerivation (finalAttrs: {
pname = "telegram-desktop";
version = "5.6.3";
inherit pname;
inherit (unwrapped) version meta passthru;

src = fetchFromGitHub {
owner = "telegramdesktop";
repo = "tdesktop";
rev = "v${finalAttrs.version}";
fetchSubmodules = true;
hash = "sha256-frz425V5eRulNVxCf457TWQAzU/f9/szD/sx3/LYQ2Y=";
};

postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioInputALSA.cpp \
--replace-fail '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"'
substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioOutputALSA.cpp \
--replace-fail '"libasound.so.2"' '"${alsa-lib}/lib/libasound.so.2"'
substituteInPlace Telegram/ThirdParty/libtgvoip/os/linux/AudioPulse.cpp \
--replace-fail '"libpulse.so.0"' '"${libpulseaudio}/lib/libpulse.so.0"'
'' + lib.optionalString (stdenv.hostPlatform.isLinux && withWebKitGTK) ''
substituteInPlace Telegram/lib_webview/webview/platform/linux/webview_linux_webkitgtk_library.cpp \
--replace-fail '"libwebkit2gtk-4.1.so.0"' '"${webkitgtk_4_1}/lib/libwebkit2gtk-4.1.so.0"'
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace Telegram/lib_webrtc/webrtc/platform/mac/webrtc_environment_mac.mm \
--replace-fail kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster
'';
inherit unwrapped;

# Avoid double-wrapping
dontWrapGApps = true;

# Wrapping the inside of the app bundles, avoiding double-wrapping
dontWrapQtApps = stdenv.hostPlatform.isDarwin;
nativeBuildInputs =
[
wrapQtAppsHook
]
++ lib.optionals withWebkit [
wrapGAppsHook3
];

nativeBuildInputs = [
pkg-config
cmake
ninja
python3
wrapQtAppsHook
] ++ lib.optionals stdenv.hostPlatform.isLinux [
# to build bundled libdispatch
clang
gobject-introspection
] ++ lib.optionals (stdenv.hostPlatform.isLinux && withWebKitGTK) [
wrapGAppsHook3
];
buildInputs =
[
qtbase
qtimageformats
qtsvg
]
++ lib.optionals stdenv.hostPlatform.isLinux [
qtwayland
]
++ lib.optionals withWebkit [
glib-networking
];

buildInputs = [
qtbase
qtimageformats
qtsvg
lz4
xxHash
ffmpeg
openalSoft
minizip
libopus
range-v3
tl-expected
rnnoise
tg_owt
microsoft-gsl
boost
ada
] ++ lib.optionals stdenv.hostPlatform.isLinux [
protobuf
qtwayland
kcoreaddons
alsa-lib
libpulseaudio
hunspell
jemalloc
] ++ lib.optionals (stdenv.hostPlatform.isLinux && withWebKitGTK) [
glib-networking
webkitgtk_4_1
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
apple-sdk_15
libicns
qtWrapperArgs = lib.optionals (stdenv.hostPlatform.isLinux && withWebkit) [
"--prefix"
"LD_LIBRARY_PATH"
":"
(lib.makeLibraryPath [ webkitgtk_4_1 ])
];

cmakeFlags = [
# We're allowed to used the API ID of the Snap package:
(lib.cmakeFeature "TDESKTOP_API_ID" "611335")
(lib.cmakeFeature "TDESKTOP_API_HASH" "d524b414d21f4d37f08684c1df41ac9c")
];
dontUnpack = true;
dontWrapGApps = true;
dontWrapQtApps = stdenv.hostPlatform.isDarwin;

installPhase = lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
cp -r ${finalAttrs.meta.mainProgram}.app $out/Applications
ln -s $out/{Applications/${finalAttrs.meta.mainProgram}.app/Contents/MacOS,bin}
installPhase = ''
runHook preInstall
cp -r "$unwrapped" "$out"
runHook postInstall
'';

preFixup = lib.optionalString (stdenv.hostPlatform.isLinux && withWebKitGTK) ''
preFixup = lib.optionalString (stdenv.hostPlatform.isLinux && withWebkit) ''
qtWrapperArgs+=("''${gappsWrapperArgs[@]}")
'';

postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
wrapQtApp $out/Applications/${finalAttrs.meta.mainProgram}.app/Contents/MacOS/${finalAttrs.meta.mainProgram}
'';

passthru = {
inherit tg_owt;
updateScript = nix-update-script { };
};

meta = {
description = "Telegram Desktop messaging app";
longDescription = ''
Desktop client for the Telegram messenger, based on the Telegram API and
the MTProto secure protocol.
postFixup =
lib.optionalString stdenv.hostPlatform.isDarwin ''
wrapQtApp "$out/Applications/${finalAttrs.meta.mainProgram}.app/Contents/MacOS/${finalAttrs.meta.mainProgram}"
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
substituteInPlace $out/share/dbus-1/services/* \
--replace-fail "$unwrapped" "$out"
'';
license = lib.licenses.gpl3Only;
platforms = lib.platforms.all;
homepage = "https://desktop.telegram.org/";
changelog = "https://github.com/telegramdesktop/tdesktop/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ nickcao ];
mainProgram = if stdenv.hostPlatform.isLinux then "telegram-desktop" else "Telegram";
};
})
Loading

0 comments on commit 2a14d5d

Please sign in to comment.