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