From 9eee76ae0d5961994183eba52326320e467b74b4 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Sat, 3 Jun 2023 09:47:36 +0800 Subject: [PATCH 1/2] telegram-desktop: use nix-update-script --- .../telegram/telegram-desktop/default.nix | 4 +- .../telegram/telegram-desktop/tg_owt.nix | 4 +- .../telegram/telegram-desktop/update.py | 73 ------------------- 3 files changed, 5 insertions(+), 76 deletions(-) delete mode 100755 pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/update.py 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 28f3c363bbd8..4c113e7f2d04 100644 --- a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix +++ b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix @@ -55,6 +55,7 @@ , microsoft-gsl , rlottie , stdenv +, nix-update-script }: # Main reference: @@ -74,7 +75,6 @@ in stdenv.mkDerivation rec { pname = "telegram-desktop"; version = "4.8.1"; - # Note: Update via pkgs/applications/networking/instant-messengers/telegram/tdesktop/update.py src = fetchFromGitHub { owner = "telegramdesktop"; @@ -186,7 +186,7 @@ stdenv.mkDerivation rec { passthru = { inherit tg_owt; - updateScript = ./update.py; + updateScript = nix-update-script { }; }; meta = with lib; { 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 025f5f83ecf3..bc123e212d07 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, valgrind, libepoxy, libglvnd +, mesa, libepoxy, libglvnd, unstableGitUpdater }: stdenv.mkDerivation { @@ -54,6 +54,8 @@ stdenv.mkDerivation { abseil-cpp openh264 usrsctp libevent libvpx openssl ]; + passthru.updateScript = unstableGitUpdater { }; + meta = with lib; { license = licenses.bsd3; maintainers = with maintainers; [ oxalica ]; diff --git a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/update.py b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/update.py deleted file mode 100755 index 89e40218623b..000000000000 --- a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/update.py +++ /dev/null @@ -1,73 +0,0 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i python3 -p python3 nix nix-prefetch-git - -import fileinput -import json -import os -import re -import subprocess - -from datetime import datetime -from urllib.request import urlopen, Request - - -DIR = os.path.dirname(os.path.abspath(__file__)) -HEADERS = {'Accept': 'application/vnd.github.v3+json'} - - -def github_api_request(endpoint): - base_url = 'https://api.github.com/' - request = Request(base_url + endpoint, headers=HEADERS) - with urlopen(request) as http_response: - return json.loads(http_response.read().decode('utf-8')) - - -def get_commit_date(repo, sha): - url = f'https://api.github.com/repos/{repo}/commits/{sha}' - request = Request(url, headers=HEADERS) - with urlopen(request) as http_response: - commit = json.loads(http_response.read().decode()) - date = commit['commit']['committer']['date'].rstrip('Z') - date = datetime.fromisoformat(date).date().isoformat() - return 'unstable-' + date - - -def nix_prefetch_git(url, rev): - """Prefetches the requested Git revision (incl. submodules) of the given repository URL.""" - print(f'nix-prefetch-git {url} {rev}') - out = subprocess.check_output(['nix-prefetch-git', '--quiet', '--url', url, '--rev', rev, '--fetch-submodules']) - return json.loads(out)['sha256'] - - -def nix_prefetch_url(url, unpack=False): - """Prefetches the content of the given URL.""" - print(f'nix-prefetch-url {url}') - options = ['--type', 'sha256'] - if unpack: - options += ['--unpack'] - out = subprocess.check_output(['nix-prefetch-url'] + options + [url]) - return out.decode('utf-8').rstrip() - - -def update_file(relpath, version, sha256, rev=None): - file_path = os.path.join(DIR, relpath) - with fileinput.FileInput(file_path, inplace=True) as f: - for line in f: - result = line - result = re.sub(r'^ version = ".+";', f' version = "{version}";', result) - result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{sha256}";', result) - if rev: - result = re.sub(r'^ rev = ".*";', f' rev = "{rev}";', result) - print(result, end='') - - -if __name__ == "__main__": - tdesktop_tag = github_api_request('repos/telegramdesktop/tdesktop/releases/latest')['tag_name'] - tdesktop_version = tdesktop_tag.lstrip('v') - tdesktop_hash = nix_prefetch_git('https://github.com/telegramdesktop/tdesktop.git', tdesktop_tag) - update_file('default.nix', tdesktop_version, tdesktop_hash) - tg_owt_ref = github_api_request('repos/desktop-app/tg_owt/commits/master')['sha'] - tg_owt_version = get_commit_date('desktop-app/tg_owt', tg_owt_ref) - tg_owt_hash = nix_prefetch_git('https://github.com/desktop-app/tg_owt.git', tg_owt_ref) - update_file('tg_owt.nix', tg_owt_version, tg_owt_hash, tg_owt_ref) - tg_owt_ref = github_api_request('repos/desktop-app/tg_owt/commits/master')['sha'] From 4fb5325fdffde1eb457d819a46d8fe08ee1ca4a2 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Fri, 2 Jun 2023 14:39:06 +0800 Subject: [PATCH 2/2] telegram-desktop: 4.8.1 -> 4.8.3 --- .../telegram/telegram-desktop/default.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 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 4c113e7f2d04..3fa19c21ba7f 100644 --- a/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix +++ b/pkgs/applications/networking/instant-messengers/telegram/telegram-desktop/default.nix @@ -6,6 +6,7 @@ , cmake , ninja , python3 +, gobject-introspection , wrapGAppsHook , wrapQtAppsHook , extra-cmake-modules @@ -13,8 +14,9 @@ , qtwayland , qtsvg , qtimageformats -, qt5compat , gtk3 +, boost +, fmt , libdbusmenu , lz4 , xxHash @@ -74,14 +76,14 @@ let in stdenv.mkDerivation rec { pname = "telegram-desktop"; - version = "4.8.1"; + version = "4.8.3"; src = fetchFromGitHub { owner = "telegramdesktop"; repo = "tdesktop"; rev = "v${version}"; fetchSubmodules = true; - sha256 = "0mxxfh70dffkrq76nky3pwrk10s1q4ahxx2ddb58dz8igq6pl4zi"; + hash = "sha256-fvg9SFHRHeJVogYQ+vyVqGyLGnOjM5Osi3H0SNGe9fY="; }; patches = [ @@ -103,6 +105,8 @@ stdenv.mkDerivation rec { --replace '"libpulse.so.0"' '"${libpulseaudio}/lib/libpulse.so.0"' substituteInPlace Telegram/lib_webview/webview/platform/linux/webview_linux_webkitgtk_library.cpp \ --replace '"libwebkitgtk-6.0.so.4"' '"${webkitgtk_6_0}/lib/libwebkitgtk-6.0.so.4"' + substituteInPlace cmake/external/glib/CMakeLists.txt \ + --replace 'add_subdirectory(cppgir)' 'add_subdirectory(cppgir EXCLUDE_FROM_ALL)' ''; # We want to run wrapProgram manually (with additional parameters) @@ -114,6 +118,7 @@ stdenv.mkDerivation rec { cmake ninja python3 + gobject-introspection wrapGAppsHook wrapQtAppsHook extra-cmake-modules @@ -124,8 +129,9 @@ stdenv.mkDerivation rec { qtwayland qtsvg qtimageformats - qt5compat gtk3 + boost + fmt libdbusmenu lz4 xxHash @@ -174,6 +180,11 @@ stdenv.mkDerivation rec { "-DDESKTOP_APP_USE_PACKAGED_FONTS=OFF" ]; + preBuild = '' + # for cppgir to locate gir files + export GI_GIR_PATH="$XDG_DATA_DIRS" + ''; + postFixup = '' # This is necessary to run Telegram in a pure environment. # We also use gappsWrapperArgs from wrapGAppsHook.