|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + dpkg, |
| 5 | + autoPatchelfHook, |
| 6 | + alsa-lib, |
| 7 | + at-spi2-core, |
| 8 | + libtool, |
| 9 | + libxkbcommon, |
| 10 | + nspr, |
| 11 | + mesa, |
| 12 | + libtiff, |
| 13 | + udev, |
| 14 | + gtk3, |
| 15 | + libsForQt5, |
| 16 | + xorg, |
| 17 | + cups, |
| 18 | + pango, |
| 19 | + libjpeg, |
| 20 | + gtk2, |
| 21 | + gdk-pixbuf, |
| 22 | + libpulseaudio, |
| 23 | + libbsd, |
| 24 | + libusb1, |
| 25 | + libmysqlclient, |
| 26 | + llvmPackages, |
| 27 | + dbus, |
| 28 | + gcc-unwrapped, |
| 29 | + freetype, |
| 30 | + curl, |
| 31 | + makeWrapper, |
| 32 | + runCommandLocal, |
| 33 | + cacert, |
| 34 | + coreutils, |
| 35 | +}: |
| 36 | +let |
| 37 | + pkgVersion = "12.1.0.17900"; |
| 38 | + url = "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2023/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}_amd64.deb"; |
| 39 | + hash = "sha256-i2EVCmDLE2gx7l2aAo+fW8onP/z+xlPIbQYwKhQ46+o="; |
| 40 | + uri = builtins.replaceStrings [ "https://wps-linux-personal.wpscdn.cn" ] [ "" ] url; |
| 41 | + securityKey = "7f8faaaa468174dc1c9cd62e5f218a5b"; |
| 42 | +in |
| 43 | +stdenv.mkDerivation rec { |
| 44 | + pname = "wpsoffice-cn"; |
| 45 | + version = pkgVersion; |
| 46 | + |
| 47 | + src = |
| 48 | + runCommandLocal "wps-office_${version}_amd64.deb" |
| 49 | + { |
| 50 | + outputHashMode = "recursive"; |
| 51 | + outputHashAlgo = "sha256"; |
| 52 | + outputHash = hash; |
| 53 | + |
| 54 | + nativeBuildInputs = [ |
| 55 | + curl |
| 56 | + coreutils |
| 57 | + ]; |
| 58 | + |
| 59 | + impureEnvVars = lib.fetchers.proxyImpureEnvVars; |
| 60 | + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; |
| 61 | + } |
| 62 | + '' |
| 63 | + timestamp10=$(date '+%s') |
| 64 | + md5hash=($(echo -n "${securityKey}${uri}$timestamp10" | md5sum)) |
| 65 | + curl \ |
| 66 | + --retry 3 --retry-delay 3 \ |
| 67 | + "${url}?t=$timestamp10&k=$md5hash" \ |
| 68 | + > $out |
| 69 | + ''; |
| 70 | + |
| 71 | + unpackCmd = "dpkg -x $src ."; |
| 72 | + sourceRoot = "."; |
| 73 | + |
| 74 | + nativeBuildInputs = [ |
| 75 | + dpkg |
| 76 | + autoPatchelfHook |
| 77 | + makeWrapper |
| 78 | + ]; |
| 79 | + |
| 80 | + buildInputs = [ |
| 81 | + alsa-lib |
| 82 | + at-spi2-core |
| 83 | + libtool |
| 84 | + libjpeg |
| 85 | + libxkbcommon |
| 86 | + nspr |
| 87 | + mesa |
| 88 | + libtiff |
| 89 | + udev |
| 90 | + gtk3 |
| 91 | + libsForQt5.qt5.qtbase |
| 92 | + xorg.libXdamage |
| 93 | + xorg.libXtst |
| 94 | + xorg.libXv |
| 95 | + gtk2 |
| 96 | + gdk-pixbuf |
| 97 | + libpulseaudio |
| 98 | + xorg.libXScrnSaver |
| 99 | + xorg.libXxf86vm |
| 100 | + libbsd |
| 101 | + libusb1 |
| 102 | + libmysqlclient |
| 103 | + llvmPackages.openmp |
| 104 | + dbus |
| 105 | + libsForQt5.fcitx5-qt |
| 106 | + ]; |
| 107 | + |
| 108 | + dontWrapQtApps = true; |
| 109 | + |
| 110 | + runtimeDependencies = map lib.getLib [ |
| 111 | + cups |
| 112 | + pango |
| 113 | + freetype |
| 114 | + gcc-unwrapped.lib |
| 115 | + ]; |
| 116 | + |
| 117 | + autoPatchelfIgnoreMissingDeps = [ |
| 118 | + # distribution is missing libkappessframework.so |
| 119 | + "libkappessframework.so" |
| 120 | + # qt4 support is deprecated |
| 121 | + "libQtCore.so.4" |
| 122 | + "libQtNetwork.so.4" |
| 123 | + "libQtXml.so.4" |
| 124 | + # file manager integration. Not needed |
| 125 | + "libnautilus-extension.so.1" |
| 126 | + "libcaja-extension.so.1" |
| 127 | + "libpeony.so.3" |
| 128 | + # libuof.so is a exclusive library in WPS. No need to repatch it |
| 129 | + "libuof.so" |
| 130 | + ]; |
| 131 | + |
| 132 | + installPhase = '' |
| 133 | + runHook preInstall |
| 134 | + prefix=$out/opt/kingsoft/wps-office |
| 135 | + mkdir -p $out |
| 136 | + cp -r opt $out |
| 137 | + cp -r usr/* $out |
| 138 | + for i in wps wpp et wpspdf; do |
| 139 | + substituteInPlace $out/bin/$i \ |
| 140 | + --replace /opt/kingsoft/wps-office $prefix |
| 141 | + done |
| 142 | + for i in $out/share/applications/*;do |
| 143 | + substituteInPlace $i \ |
| 144 | + --replace /usr/bin $out/bin |
| 145 | + done |
| 146 | + # need system freetype and gcc lib to run properly |
| 147 | + for i in wps wpp et wpspdf wpsoffice; do |
| 148 | + wrapProgram $out/opt/kingsoft/wps-office/office6/$i \ |
| 149 | + --set LD_PRELOAD "${freetype}/lib/libfreetype.so" \ |
| 150 | + --set LD_LIBRARY_PATH "${lib.makeLibraryPath [ gcc-unwrapped.lib ]}" |
| 151 | + done |
| 152 | + runHook postInstall |
| 153 | + ''; |
| 154 | + |
| 155 | + preFixup = '' |
| 156 | + # The following libraries need libtiff.so.5, but nixpkgs provides libtiff.so.6 |
| 157 | + 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} |
| 158 | + patchelf --replace-needed libtiff.so.5 libtiff.so $out/opt/kingsoft/wps-office/office6/addons/ksplitmerge/libksplitmergeapp.so |
| 159 | + patchelf --add-needed libtiff.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so |
| 160 | + # Fix: Wrong JPEG library version: library is 62, caller expects 80 |
| 161 | + patchelf --add-needed libjpeg.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so |
| 162 | + # dlopen dependency |
| 163 | + patchelf --add-needed libudev.so.1 $out/opt/kingsoft/wps-office/office6/addons/cef/libcef.so |
| 164 | + ''; |
| 165 | + |
| 166 | + meta = with lib; { |
| 167 | + description = "Office suite, formerly Kingsoft Office"; |
| 168 | + homepage = "https://www.wps.com"; |
| 169 | + platforms = [ "x86_64-linux" ]; |
| 170 | + sourceProvenance = with sourceTypes; [ binaryNativeCode ]; |
| 171 | + hydraPlatforms = [ ]; |
| 172 | + license = licenses.unfreeRedistributable; |
| 173 | + maintainers = with maintainers; [ |
| 174 | + mlatus |
| 175 | + th0rgal |
| 176 | + rewine |
| 177 | + pokon548 |
| 178 | + ]; |
| 179 | + }; |
| 180 | +} |
0 commit comments