From a1ec97d3a24abbec8fb04d78df21098388555957 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sat, 3 Oct 2026 00:13:53 +0800 Subject: [PATCH] refactor(bwraps): source wechat from nixpkgs-master and reuse its AppImage Reuse the already-extracted, libtiff-patched AppImage from the nixpkgs wechat package (`wechat.src`) instead of keeping our own CDN URLs and hashes, which had to be refreshed whenever Tencent replaced the versionless files. Take the package from nixpkgs-master, which carries the newest builds. --- hardening/bwraps/default.nix | 4 ++- hardening/bwraps/wechat.nix | 51 +++++++++--------------------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/hardening/bwraps/default.nix b/hardening/bwraps/default.nix index fafbd2e6..011d1406 100644 --- a/hardening/bwraps/default.nix +++ b/hardening/bwraps/default.nix @@ -1,8 +1,10 @@ +{ pkgs-master, ... }: { nixpkgs.overlays = [ (_: super: { bwraps = { - wechat = super.callPackage ./wechat.nix { }; + # Track WeChat from nixpkgs-master, which carries the newest builds. + wechat = super.callPackage ./wechat.nix { wechat = pkgs-master.wechat; }; }; }) ]; diff --git a/hardening/bwraps/wechat.nix b/hardening/bwraps/wechat.nix index a0a5dc27..a64bac90 100644 --- a/hardening/bwraps/wechat.nix +++ b/hardening/bwraps/wechat.nix @@ -4,53 +4,26 @@ # - https://docs.flatpak.org/en/latest/manifests.html # - https://docs.flatpak.org/en/latest/sandbox-permissions.html # -# TODO nixpkgs' `wechat` package hardcodes its AppImage wrapper args and does not -# expose them for `.override`, so we repack it here to add our bubblewrap sandbox -# (bind mounts, tmpfs /home, IME env). Upstream override support: -# https://github.com/NixOS/nixpkgs/pull/358977 +# We repack WeChat ourselves because nixpkgs' `wechat` package hardcodes its +# AppImage wrapper args and does not expose them for `.override`, so there is no +# way to add our bubblewrap sandbox (bind mounts, tmpfs /home, IME env) through +# it. We reuse its already-extracted, libtiff-patched AppImage (`wechat.src`), +# so the version and source hash stay maintained by nixpkgs. +# Upstream override support: https://github.com/NixOS/nixpkgs/pull/358977 { appimageTools, - fetchurl, - stdenvNoCC, + wechat, }: let pname = "wechat"; - # https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/we/wechat/package.nix - sources = { - # direct CDN urls, pinned by hash (same approach as nixpkgs' wechat package) - # archive.org snapshots are not used because the CDN serves different builds per edge - # NOTE: Tencent replaces the file behind these versionless URLs, so the hashes - # must be refreshed with `nix store prefetch-file` whenever they stop matching. - # Last refreshed: 2026-09-19. - aarch64-linux = { - version = "4.1.1.8"; - src = fetchurl { - url = "https://dldir1v6.qq.com/weixin/Universal/Linux/WeChatLinux_arm64.AppImage"; - hash = "sha256-zihf1qzRuhY2oKSP3qqIm3bS3/xWZRjRpfONxDe6kRc="; - }; - }; - x86_64-linux = { - version = "4.1.1.8"; - src = fetchurl { - url = "https://dldir1v6.qq.com/weixin/Universal/Linux/WeChatLinux_x86_64.AppImage"; - hash = "sha256-T1StKQLs1vb9xWgLc1R/gNVCO/RwsBI3pXmi5bPK7us="; - }; - }; - }; - - inherit (stdenvNoCC.hostPlatform) system; - inherit (sources.${system} or (throw "Unsupported system: ${system}")) version src; - + # nixpkgs' wechat package already extracted the AppImage and applied the + # libtiff.so.5 fix; reuse it so version/hash stay maintained upstream. # https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/we/wechat/linux.nix - appimageContents = appimageTools.extract { - inherit pname version src; - postExtract = '' - patchelf --replace-needed libtiff.so.5 libtiff.so $out/opt/wechat/wechat - ''; - }; + appimageContents = wechat.src; in appimageTools.wrapAppImage { - inherit pname version; + inherit pname; + inherit (wechat) version; src = appimageContents;