1{
2 lib,
3 stdenv,
4 dpkg,
5 autoPatchelfHook,
6 alsa-lib,
7 at-spi2-core,
8 libtool,
9 libxkbcommon,
10 nspr,
11 libgbm,
12 libtiff,
13 udev,
14 gtk3,
15 qtbase,
16 xorg,
17 cups,
18 pango,
19 runCommandLocal,
20 curl,
21 coreutils,
22 cacert,
23 libjpeg,
24 useChineseVersion ? false,
25}:
26let
27 pkgVersion = "11.1.0.11723";
28 url =
29 if useChineseVersion then
30 "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}_amd64.deb"
31 else
32 "https://wdl1.pcfg.cache.wpscdn.com/wpsdl/wpsoffice/download/linux/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}.XA_amd64.deb";
33 hash =
34 if useChineseVersion then
35 "sha256-vpXK8YyjqhFdmtajO6ZotYACpe5thMct9hwUT3advUM="
36 else
37 "sha256-o8njvwE/UsQpPuLyChxGAZ4euvwfuaHxs5pfUvcM7kI=";
38 uri = builtins.replaceStrings [ "https://wps-linux-personal.wpscdn.cn" ] [ "" ] url;
39 securityKey = "7f8faaaa468174dc1c9cd62e5f218a5b";
40in
41stdenv.mkDerivation rec {
42 pname = "wpsoffice";
43 version = pkgVersion;
44
45 src =
46 runCommandLocal
47 (
48 if useChineseVersion then
49 "wps-office_${version}_amd64.deb"
50 else
51 "wps-office_${version}.XA_amd64.deb"
52 )
53 {
54 outputHashMode = "recursive";
55 outputHashAlgo = "sha256";
56 outputHash = hash;
57
58 nativeBuildInputs = [
59 curl
60 coreutils
61 ];
62
63 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
64 SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
65 }
66 ''
67 timestamp10=$(date '+%s')
68 md5hash=($(echo -n "${securityKey}${uri}$timestamp10" | md5sum))
69
70 curl \
71 --retry 3 --retry-delay 3 \
72 "${url}?t=$timestamp10&k=$md5hash" \
73 > $out
74 '';
75
76 unpackCmd = "dpkg -x $src .";
77 sourceRoot = ".";
78
79 nativeBuildInputs = [
80 dpkg
81 autoPatchelfHook
82 ];
83
84 buildInputs = [
85 alsa-lib
86 at-spi2-core
87 libtool
88 libjpeg
89 libxkbcommon
90 nspr
91 libgbm
92 libtiff
93 udev
94 gtk3
95 qtbase
96 xorg.libXdamage
97 xorg.libXtst
98 xorg.libXv
99 ];
100
101 dontWrapQtApps = true;
102
103 runtimeDependencies = map lib.getLib [
104 cups
105 pango
106 ];
107
108 autoPatchelfIgnoreMissingDeps = [
109 # distribution is missing libkappessframework.so
110 "libkappessframework.so"
111 # qt4 support is deprecated
112 "libQtCore.so.4"
113 "libQtNetwork.so.4"
114 "libQtXml.so.4"
115 ];
116
117 installPhase = ''
118 runHook preInstall
119 prefix=$out/opt/kingsoft/wps-office
120 mkdir -p $out
121 cp -r opt $out
122 cp -r usr/* $out
123 for i in wps wpp et wpspdf; do
124 substituteInPlace $out/bin/$i \
125 --replace /opt/kingsoft/wps-office $prefix
126 done
127 for i in $out/share/applications/*;do
128 substituteInPlace $i \
129 --replace /usr/bin $out/bin
130 done
131 runHook postInstall
132 '';
133
134 preFixup = ''
135 # The following libraries need libtiff.so.5, but nixpkgs provides libtiff.so.6
136 patchelf --replace-needed libtiff.so.5 libtiff.so $out/opt/kingsoft/wps-office/office6/{libpdfmain.so,libqpdfpaint.so,qt/plugins/imageformats/libqtiff.so,addons/pdfbatchcompression/libpdfbatchcompressionapp.so}
137 patchelf --add-needed libtiff.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so
138 # Fix: Wrong JPEG library version: library is 62, caller expects 80
139 patchelf --add-needed libjpeg.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so
140 # dlopen dependency
141 patchelf --add-needed libudev.so.1 $out/opt/kingsoft/wps-office/office6/addons/cef/libcef.so
142 '';
143
144 meta = with lib; {
145 description = "Office suite, formerly Kingsoft Office";
146 homepage = "https://www.wps.com";
147 platforms = [ "x86_64-linux" ];
148 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
149 hydraPlatforms = [ ];
150 license = licenses.unfreeRedistributable;
151 maintainers = with maintainers; [
152 mlatus
153 th0rgal
154 rewine
155 pokon548
156 ];
157 };
158}