tuicam: init at 0.0.2 (#377825)
[NixPkgs.git] / pkgs / by-name / we / wechat-uos / package.nix
blob0791fd971288a7fed427416506e9376b5b824d37
2   stdenvNoCC,
3   stdenv,
4   lib,
5   fetchurl,
6   dpkg,
7   nss,
8   nspr,
9   xorg,
10   pango,
11   zlib,
12   atkmm,
13   libdrm,
14   libxkbcommon,
15   xcbutilwm,
16   xcbutilimage,
17   xcbutilkeysyms,
18   xcbutilrenderutil,
19   libgbm,
20   alsa-lib,
21   wayland,
22   atk,
23   qt6,
24   at-spi2-atk,
25   at-spi2-core,
26   dbus,
27   cups,
28   gtk3,
29   libxml2,
30   cairo,
31   freetype,
32   fontconfig,
33   vulkan-loader,
34   gdk-pixbuf,
35   libexif,
36   ffmpeg,
37   pulseaudio,
38   systemd,
39   libuuid,
40   expat,
41   bzip2,
42   glib,
43   libva,
44   libGL,
45   libnotify,
46   buildFHSEnv,
47   writeShellScript,
49 let
50   # zerocallusedregs hardening breaks WeChat
51   glibcWithoutHardening = stdenv.cc.libc.overrideAttrs (old: {
52     hardeningDisable = (old.hardeningDisable or [ ]) ++ [ "zerocallusedregs" ];
53   });
55   wechat-uos-env = stdenvNoCC.mkDerivation {
56     meta.priority = 1;
57     name = "wechat-uos-env";
58     buildCommand = ''
59       mkdir -p $out/etc
60       mkdir -p $out/usr/bin
61       mkdir -p $out/usr/share
62       mkdir -p $out/opt
63       mkdir -p $out/var
65       ln -s ${wechat}/opt/* $out/opt/
66     '';
67     preferLocalBuild = true;
68   };
70   wechat-uos-runtime = with xorg; [
71     # Make sure our glibc without hardening gets picked up first
72     (lib.hiPrio glibcWithoutHardening)
74     stdenv.cc.cc
75     stdenv.cc.libc
76     pango
77     zlib
78     xcbutilwm
79     xcbutilimage
80     xcbutilkeysyms
81     xcbutilrenderutil
82     libX11
83     libXt
84     libXext
85     libSM
86     libICE
87     libxcb
88     libxkbcommon
89     libxshmfence
90     libXi
91     libXft
92     libXcursor
93     libXfixes
94     libXScrnSaver
95     libXcomposite
96     libXdamage
97     libXtst
98     libXrandr
99     libnotify
100     atk
101     atkmm
102     cairo
103     at-spi2-atk
104     at-spi2-core
105     alsa-lib
106     dbus
107     cups
108     gtk3
109     gdk-pixbuf
110     libexif
111     ffmpeg
112     libva
113     freetype
114     fontconfig
115     libXrender
116     libuuid
117     expat
118     glib
119     nss
120     nspr
121     libGL
122     libxml2
123     pango
124     libdrm
125     libgbm
126     vulkan-loader
127     systemd
128     wayland
129     pulseaudio
130     qt6.qt5compat
131     bzip2
132   ];
134   sources = import ./sources.nix;
136   wechat = stdenvNoCC.mkDerivation rec {
137     pname = "wechat-uos";
138     version = sources.version;
140     src =
141       {
142         x86_64-linux = fetchurl {
143           url = sources.amd64_url;
144           hash = sources.amd64_hash;
145         };
146         aarch64-linux = fetchurl {
147           url = sources.arm64_url;
148           hash = sources.arm64_hash;
149         };
150         loongarch64-linux = fetchurl {
151           url = sources.loongarch64_url;
152           hash = sources.loongarch64_hash;
153         };
154       }
155       .${stdenv.system} or (throw "${pname}-${version}: ${stdenv.system} is unsupported.");
157     nativeBuildInputs = [ dpkg ];
159     unpackPhase = ''
160       runHook preUnpack
162       dpkg -x $src ./wechat-uos
164       runHook postUnpack
165     '';
167     # Use ln for license to prevent being garbage collection
168     installPhase = ''
169       runHook preInstall
170       mkdir -p $out
172       cp -r wechat-uos/* $out
174       runHook postInstall
175     '';
177     meta = with lib; {
178       description = "Messaging app";
179       homepage = "https://weixin.qq.com/";
180       license = licenses.unfree;
181       platforms = [
182         "x86_64-linux"
183         "aarch64-linux"
184         "loongarch64-linux"
185       ];
186       sourceProvenance = with sourceTypes; [ binaryNativeCode ];
187       maintainers = with maintainers; [
188         pokon548
189         xddxdd
190       ];
191       mainProgram = "wechat-uos";
192     };
193   };
195 buildFHSEnv {
196   inherit (wechat) pname version meta;
197   runScript = writeShellScript "wechat-uos-launcher" ''
198     export QT_QPA_PLATFORM=xcb
199     export QT_AUTO_SCREEN_SCALE_FACTOR=1
200     export LD_LIBRARY_PATH=${lib.makeLibraryPath wechat-uos-runtime}
202     if [[ ''${XMODIFIERS} =~ fcitx ]]; then
203       export QT_IM_MODULE=fcitx
204       export GTK_IM_MODULE=fcitx
205     elif [[ ''${XMODIFIERS} =~ ibus ]]; then
206       export QT_IM_MODULE=ibus
207       export GTK_IM_MODULE=ibus
208       export IBUS_USE_PORTAL=1
209     fi
211     ${wechat.outPath}/opt/apps/com.tencent.wechat/files/wechat
212   '';
213   extraInstallCommands = ''
214     mkdir -p $out/share/applications
215     mkdir -p $out/share/icons
216     cp -r ${wechat.outPath}/opt/apps/com.tencent.wechat/entries/applications/com.tencent.wechat.desktop $out/share/applications
217     cp -r ${wechat.outPath}/opt/apps/com.tencent.wechat/entries/icons/* $out/share/icons/
219     substituteInPlace $out/share/applications/com.tencent.wechat.desktop \
220       --replace-quiet 'Exec=/usr/bin/wechat' "Exec=$out/bin/wechat-uos --"
221   '';
222   targetPkgs = pkgs: [ wechat-uos-env ];
224   passthru.updateScript = ./update.sh;
226   extraOutputsToInstall = [
227     "usr"
228     "var/lib/uos"
229     "var/uos"
230     "etc"
231   ];