Skip to content

Commit

Permalink
add wechat
Browse files Browse the repository at this point in the history
  • Loading branch information
QixYuanmeng committed Aug 19, 2024
1 parent fcafe2d commit d69f0dd
Show file tree
Hide file tree
Showing 19 changed files with 693 additions and 60 deletions.
343 changes: 313 additions & 30 deletions flake.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,7 @@
# inputs.nixpkgs.follows = "nixpkgs";
};
nur.url = "github:nix-community/NUR";

daeuniverse.url = "github:daeuniverse/flake.nix";
};
}
15 changes: 15 additions & 0 deletions home/base/core/java.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ pkgs, ... }:

let
additionalJDKs = with pkgs; [ jdk17 jdk8 jdk22 ];
in
{
# ...
programs.java = { /*...*/ };

home.sessionPath = [ "$HOME/.jdks" ];
home.file = (builtins.listToAttrs (builtins.map (jdk: {
name = ".java/${jdk.version}";
value = { source = jdk; };
}) additionalJDKs));
}
1 change: 1 addition & 0 deletions home/base/gui/dev-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
# IDEs
jetbrains.pycharm-professional
jetbrains.idea-ultimate

];
}
4 changes: 4 additions & 0 deletions home/base/gui/media.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
pkgs,
config,
pkgs-unstable,
...
}:

# processing audio/video
{

home.packages = with pkgs; [
ffmpeg-full

# images
viu # Terminal image viewer with native support for iTerm and Kitty
imagemagick
graphviz
v4l-utils
];
}
1 change: 1 addition & 0 deletions home/linux/base/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
c = config.xdg.configHome;
cache = config.xdg.cacheHome;
in rec {

home.homeDirectory = "/home/${myvars.username}";

# environment variables that always set at login
Expand Down
4 changes: 4 additions & 0 deletions home/linux/gui/base/custom/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{pkgs, pkgs-unstable, ... }:
{
wechat-universal-bwrap = pkgs.callPackage ./wechat-universal-bwrap { };
}
290 changes: 290 additions & 0 deletions home/linux/gui/base/custom/wechat-universal-bwrap/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{ stdenv, fetchurl
, buildFHSUserEnvBubblewrap
, writeShellScript
, makeDesktopItem
, writeShellScriptBin
, rpmextract
, makeWrapper
, autoPatchelfHook
, copyDesktopItems
, lib

, alsa-lib
, at-spi2-atk
, at-spi2-core
, mesa
, nss
, pango
, xdg-desktop-portal
, xdg-user-dirs
, xorg
, cairo
, gtk3
, gtk4
, libglvnd
, libpulseaudio
, libva
, pciutils
, udev
, libxkbcommon

}:
let
libraries = [
alsa-lib
at-spi2-atk
at-spi2-core
mesa
nss
pango
xdg-desktop-portal
xdg-user-dirs
xorg.libXcursor
xorg.libXdamage
xorg.libXrandr
xorg.xcbutilimage
xorg.xcbutilkeysyms
xorg.xcbutilrenderutil
xorg.xcbutilwm
xorg.libXcomposite
cairo
gtk3
gtk4
libglvnd
libpulseaudio
libva
pciutils
udev
libxkbcommon
];

_lib_uos = "libuosdevicea";
_pkgname = "wechat-universal";
ver = "1.0.0.242";
xdg-dir = "${xdg-user-dirs}/bin";

# From https://github.com/7Ji-PKGBUILDs/wechat-universal-bwrap
# Adapted from https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=wechat-universal-bwrap
wechat-universal-license = stdenv.mkDerivation {
pname = "${_pkgname}-license";
version = "0.0.1";
src = builtins.fetchGit {
url = "https://github.com/7Ji-PKGBUILDs/wechat-universal-bwrap.git";
ref = "master";
rev = "5e8ad25218b82b9bbacb0bd43dce2feb85998889";
};

buildPhase = ''
echo "Building ${_lib_uos}.so stub by Zephyr Lykos..."
mv libuosdevicea.Makefile Makefile
make
'';
installPhase = ''
mkdir -p $out
echo "Fixing licenses..."
install -dm755 $out/usr/lib/license
install -Dm755 ${_lib_uos}.so $out/lib/license/${_lib_uos}.so
echo "DISTRIB_ID=uos" |
install -Dm755 /dev/stdin $out/etc/lsb-release
'';
};

wechat-universal-src = stdenv.mkDerivation rec {

pname = "${_pkgname}-source";
version = "${ver}";

src = fetchurl {
url = "https://mirrors.opencloudos.tech/opencloudos/9.2/extras/x86_64/os/Packages/wechat-beta_${version}_amd64.rpm";
hash = "sha256-/5fXEfPHHL6G75Ph0EpoGvXD6V4BiPS0EQZM7SgZ1xk=";
};

nativeBuildInputs = [
rpmextract
makeWrapper
autoPatchelfHook
];
buildInputs = libraries;

unpackCmd = "rpmextract $src";
sourceRoot = ".";

installPhase = ''
mkdir -p $out
mv opt/wechat-beta opt/${_pkgname}
cp -r opt $out
'';
};


startScript = writeShellScript "wechat-start" ''
export QT_QPA_PLATFORM=xcb
if [[ ''${XMODIFIERS} =~ fcitx ]]; then
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
elif [[ ''${XMODIFIERS} =~ ibus ]]; then
export QT_IM_MODULE=ibus
export GTK_IM_MODULE=ibus
export IBUS_USE_PORTAL=1
fi
exec ${wechat-universal-src}/opt/${_pkgname}/wechat
'';

# Adapted from https://aur.archlinux.org/cgit/aur.git/tree/fake_dde-file-manager?h=wechat-universal-bwrap
fake-dde-file-manager = writeShellScriptBin "dde-file-manager" ''
_show_item=""
_item=""
for _arg in "''$@"; do
if [[ "''${_arg}" == --show-item ]]; then
_show_item='y'
else
[[ -z "''${_item}" ]] && _item="''${_arg}"
fi
done
if [[ "''${_show_item}" ]]; then
_path=$(readlink -f -- "''${_item}") # Resolve this to absolute path that's same across host / guest
echo "Fake deepin file manager: dbus-send to open ''${_path} in file manager"
if [[ -d "''${_path}" ]]; then
# WeChat pass both files and folders in the same way, if we use ShowItems for folders,
# it would open that folder's parent folder, which is not right.
_object=ShowFolders
_target=folders
else
_object=ShowItems
_target=items
fi
exec dbus-send --print-reply --dest=org.freedesktop.FileManager1 \
/org/freedesktop/FileManager1 \
org.freedesktop.FileManager1."''${_object}" \
array:string:"file://''${_path}" \
string:fake-dde-file-manager-show-"''${_target}"
# We should not fall to here, but add a fallback anyway
echo "Fake deepin file manager: fallback: xdg-open to show ''${_path} in file manager"
exec xdg-open "''${_path}"
else
echo "Fake deepin file manager: xdg-open with args ''$@"
exec xdg-open "''$@"
fi
'';
fhs = buildFHSUserEnvBubblewrap {
name = "${_pkgname}";

targetPkgs =
pkgs: [
fake-dde-file-manager
wechat-universal-license
wechat-universal-src
]
++
libraries;

runScript = startScript;

extraPreBwrapCmds = ''
# Data folder setup
# If user has declared a custom data dir, no need to query xdg for documents dir, but always resolve that to absolute path
if [[ "''${WECHAT_DATA_DIR}" ]]; then
WECHAT_DATA_DIR=$(readlink -f -- "''${WECHAT_DATA_DIR}")
else
XDG_DOCUMENTS_DIR="''${XDG_DOCUMENTS_DIR:-$(${xdg-dir}/xdg-user-dir DOCUMENTS)}"
if [[ -z "''${XDG_DOCUMENTS_DIR}" ]]; then
echo 'Error: Failed to get XDG_DOCUMENTS_DIR, refuse to continue'
exit 1
fi
WECHAT_DATA_DIR="''${XDG_DOCUMENTS_DIR}/WeChat_Data"
fi
WECHAT_FILES_DIR="''${WECHAT_DATA_DIR}/xwechat_files"
WECHAT_HOME_DIR="''${WECHAT_DATA_DIR}/home"
mkdir -p "''${WECHAT_FILES_DIR}"
mkdir -p "''${WECHAT_HOME_DIR}"
'';

extraBwrapArgs = [
"--tmpfs /home"
"--tmpfs /root"
"--bind \${WECHAT_HOME_DIR} \${HOME}"
"--bind \${WECHAT_FILES_DIR} \${WECHAT_FILES_DIR}"
"--chdir $HOME"
"--setenv QT_QPA_PLATFORM xcb"
# "--setenv QT_AUTO_SCREEN_SCALE_FACTOR 1"

"--ro-bind-try \${HOME}/.fontconfig{,}"
"--ro-bind-try \${HOME}/.fonts{,}"
"--ro-bind-try \${HOME}/.config/fontconfig{,}"
"--ro-bind-try \${HOME}/.local/share/fonts{,}"
"--ro-bind-try \${HOME}/.icons{,}"
"--ro-bind-try \${HOME}/.local/share/.icons{,}"
];

unshareUser = true;
unshareIpc = true;
unsharePid = true;
unshareNet = false;
unshareUts = true;
unshareCgroup = true;
privateTmp = true;
};
in
stdenv.mkDerivation rec {

pname = "${_pkgname}-bwrap";
version = "${ver}";

dontUnpack = true;

buildInputs = libraries;

nativeBuildInputs = [
makeWrapper
autoPatchelfHook
copyDesktopItems
];

installPhase = ''
mkdir -p $out/bin
echo 'Installing icons...'
# for res in 16 32 48 64 128 256; do
# install -Dm644 \
# ${wechat-universal-src}/opt/apps/com.tencent.wechat/entries/icons/hicolor/''${res}x''${res}/apps/com.tencent.wechat.png \
# $out/share/icons/hicolor/''${res}x''${res}/apps/${_pkgname}.png
# done
install -DTm644 ${wechat-universal-src}/opt/${_pkgname}/icons/wechat.png $out/usr/share/icons/hicolor/256x256/apps/${_pkgname}.png
makeWrapper ${fhs}/bin/${_pkgname} $out/bin/${pname}
runHook postInstall
'';

desktopItems = [
(makeDesktopItem {
name = "${_pkgname}";
desktopName = "WeChat Universal";
exec = "${pname} %U";
terminal = false;
icon = "${_pkgname}";
startupWMClass = "wechat";
comment = "WeChat Universal Desktop Edition";
categories = [ "Utility" "Network" "InstantMessaging" "Chat" ];
keywords = [
"wechat"
"weixin"
"${_pkgname}"
];
extraConfig = {
"Name[zh_CN]" = "微信 Universal";
"Name[zh_TW]" = "微信 Universal";
"Comment[zh_CN]" = "微信桌面版 Universal";
"Comment[zh_TW]" = "微信桌面版 Universal";
};
})
];

meta = with lib; {
description = ''
WeChat desktop with sandbox enabled
(Adapted from https://aur.archlinux.org/packages/wechat-universal-bwrap)
'';
homepage = "https://weixin.qq.com/";
platforms = [ "x86_64-linux" ];
license = licenses.unfreeRedistributable;
};
}
5 changes: 3 additions & 2 deletions home/linux/gui/base/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
nur,
...
}: {

home.packages = with pkgs; [
# GUI apps
# e-book viewer(.epub/.mobi/...)
Expand All @@ -15,7 +14,7 @@
telegram-desktop
#discord
pkgs-unstable.qq # https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/networking/instant-messengers/qq

# pkgs-unstable.wechat-uos
# remote desktop(rdp connect)
remmina
freerdp # required by remmina
Expand All @@ -27,6 +26,8 @@
pkgs.nur.repos.linyinfeng.wemeet

wpsoffice-cn

feishu
];

# GitHub CLI tool
Expand Down
3 changes: 2 additions & 1 deletion home/linux/gui/hyprland/conf/hyprland.conf
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ exec-once=cp ~/.config/fcitx5/profile-bak ~/.config/fcitx5/profile # restore
exec-once=fcitx5 -d --replace # start fcitx5 daemon
bind=ALT,E,exec,pkill fcitx5 -9;sleep 1;fcitx5 -d --replace; sleep 1;fcitx5-remote -r

monitor=eDP-1,highres,auto,1
monitor=eDP-1,highres,auto,1
monitor=HDMI-A-1,1920x1080,auto-left,1
Loading

0 comments on commit d69f0dd

Please sign in to comment.