本地 patch flatpak wechat 包

2024-07-03

事出有因

是希望在NixOS上使用微信来着,但是又不想再wine,搜了下flatpak上已经有了wechat universal版,于是想无脑

flatpak install com.tencent.WeChat.flatpak

随后便遇到报错

[user@nixos:~]$ flatpak install flathub com.tencent.WeChat

Note that the directories 

'/var/lib/flatpak/exports/share'
'/home/wsl/.local/share/flatpak/exports/share'

are not in the search path set by the XDG_DATA_DIRS environment variable, so
applications installed by Flatpak may not appear on your desktop until the
session is restarted.

Looking for matches…

com.tencent.WeChat permissions:
    ipc                    network                pulseaudio              x11       devices
    file access [1]        dbus access [2]        bus ownership [3]

    [1] xdg-download
    [2] org.freedesktop.FileManager1, org.freedesktop.Notifications, org.kde.StatusNotifierWatcher
    [3] org.kde.*


        ID                          Branch         Op         Remote          Download
 1. [✗] com.tencent.WeChat          stable         i          flathub         573.2 kB / 117.4 MB

Error: While downloading https://archive2.kylinos.cn/deb/kylin/production/PART-openKylin/custom/partner/openKylin/pool/all/wechat-beta_1.0.0.238_amd64.deb: While fetching https://archive2.kylinos.cn/deb/kylin/production/PART-openKylin/custom/partner/openKylin/pool/all/wechat-beta_1.0.0.238_amd64.deb: [18] Transferred a partial file
error: Failed to install com.tencent.WeChat: While downloading https://archive2.kylinos.cn/deb/kylin/production/PART-openKylin/custom/partner/openKylin/pool/all/wechat-beta_1.0.0.238_amd64.deb: While fetching https://archive2.kylinos.cn/deb/kylin/production/PART-openKylin/custom/partner/openKylin/pool/all/wechat-beta_1.0.0.238_amd64.deb: [18] Transferred a partial file

简单排查

  • 使用chrome下载这个连接,得到结果:wechat-beta_1.0.0.238_amd64.debFailed - File incomplete
  • 看起来像是自己的问题,然后切换另外一台机器wget这个地址,也是存在报错,推测是上游服务器有问题。

着手解决

首先查找到了 flathub 上wechat包的仓库,在其中搜索这个地址,定位到了具体文件的具体位置 com.tencent.WeChat.yaml 而后克隆此仓库,修改连接

git clone https://github.com/flathub/com.tencent.WeChat.git
cd com.tencent.WeChat
sed -i 's|https://archive2.kylinos.cn/deb/kylin/production/PART-openKylin/custom/partner/openKylin/pool/all/wechat-beta_1.0.0.238_amd64.deb|https://archive2.kylinos.cn/DEB/OPENKYLIN/pool/all/wechat-beta_1.0.0.238_amd64.deb|g' com.tencent.WeChat.yaml

参照 flatpak文档进行本地打包

flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
# 打包需要flatpak-builder以及appstream
nix-shell -p flatpak-builder
nix-shell -p appstream
# 打包
flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir com.tencent.WeChat.yaml 
# 运行
flatpak run com.tencent.WeChat 

后续

原先无法下载连接过了一个小时就恢复正常了,也无法确定到底是我自己网络的问题还是上游的问题了。

参照与引用

Building your first Flatpak

sed 字符串替换

flathub WeChat仓库