Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wpsoffice-365: init at 12.8.2.18605 #353985

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 133 additions & 46 deletions pkgs/applications/office/wpsoffice/default.nix
Original file line number Diff line number Diff line change
@@ -1,72 +1,116 @@
{ lib
, stdenv
, dpkg
, autoPatchelfHook
, alsa-lib
, at-spi2-core
, libtool
, libxkbcommon
, nspr
, mesa
, libtiff
, udev
, gtk3
, qtbase
, xorg
, cups
, pango
, runCommandLocal
, curl
, coreutils
, cacert
, libjpeg
, useChineseVersion ? false
{
lib,
stdenv,
dpkg,
autoPatchelfHook,
alsa-lib,
at-spi2-core,
libtool,
libxkbcommon,
nspr,
mesa,
libtiff,
udev,
gtk3,
libsForQt5,
xorg,
cups,
pango,
libjpeg,
gtk2,
gdk-pixbuf,
libpulseaudio,
libbsd,
libusb1,
libmysqlclient,
llvmPackages,
dbus,
gcc-unwrapped,
freetype,
curl,
makeWrapper,
runCommandLocal,
cacert,
coreutils,
fetchurl,
useChineseVersion ? false,
use365Version ? false,
}:
let
pkgVersion = "11.1.0.11723";
sources = import ./sources.nix;
pkgVersion = "12.1.0.17900";
url =
if useChineseVersion then
"https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}_amd64.deb"
"https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2023/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}_amd64.deb"
else
"https://wdl1.pcfg.cache.wpscdn.com/wpsdl/wpsoffice/download/linux/${lib.last (lib.splitVersion pkgVersion)}/wps-office_${pkgVersion}.XA_amd64.deb";
hash =
if useChineseVersion then
"sha256-vpXK8YyjqhFdmtajO6ZotYACpe5thMct9hwUT3advUM="
"sha256-i2EVCmDLE2gx7l2aAo+fW8onP/z+xlPIbQYwKhQ46+o="
else
"sha256-o8njvwE/UsQpPuLyChxGAZ4euvwfuaHxs5pfUvcM7kI=";
uri = builtins.replaceStrings [ "https://wps-linux-personal.wpscdn.cn" ] [ "" ] url;
securityKey = "7f8faaaa468174dc1c9cd62e5f218a5b";
in
stdenv.mkDerivation rec {
pname = "wpsoffice";
version = pkgVersion;
version = if use365Version then sources.version else pkgVersion;

src = runCommandLocal (if useChineseVersion then "wps-office_${version}_amd64.deb" else "wps-office_${version}.XA_amd64.deb")
{
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = hash;
src =
if use365Version then
(
{
x86_64-linux = fetchurl {
url = sources.pro_amd64_url;
hash = sources.pro_amd64_hash;
};
aarch64-linux = fetchurl {
url = sources.pro_arm64_url;
hash = sources.pro_arm64_hash;
};
}
.${stdenv.system} or (throw "wpsoffice-365-${version}: ${stdenv.system} is unsupported.")
)
else if (stdenv.system == "x86_64-linux") then
runCommandLocal
(
if useChineseVersion then
"wps-office_${version}_amd64.deb"
else
"wps-office_${version}.XA_amd64.deb"
)
{
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = hash;

nativeBuildInputs = [ curl coreutils ];
nativeBuildInputs = [
curl
coreutils
];

impureEnvVars = lib.fetchers.proxyImpureEnvVars;
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
} ''
timestamp10=$(date '+%s')
md5hash=($(echo -n "${securityKey}${uri}$timestamp10" | md5sum))
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
}
''
timestamp10=$(date '+%s')
md5hash=($(echo -n "${securityKey}${uri}$timestamp10" | md5sum))

curl \
--retry 3 --retry-delay 3 \
"${url}?t=$timestamp10&k=$md5hash" \
> $out
'';
curl \
--retry 3 --retry-delay 3 \
"${url}?t=$timestamp10&k=$md5hash" \
> $out
''
else
(throw "${pname}-${version}: ${stdenv.system} is unsupported.");

unpackCmd = "dpkg -x $src .";
sourceRoot = ".";

nativeBuildInputs = [
dpkg
autoPatchelfHook
makeWrapper
];

buildInputs = [
Expand All @@ -80,17 +124,30 @@ stdenv.mkDerivation rec {
libtiff
udev
gtk3
qtbase
libsForQt5.qt5.qtbase
xorg.libXdamage
xorg.libXtst
xorg.libXv
gtk2
gdk-pixbuf
libpulseaudio
xorg.libXScrnSaver
xorg.libXxf86vm
libbsd
libusb1
libmysqlclient
llvmPackages.openmp
dbus
libsForQt5.fcitx5-qt
];

dontWrapQtApps = true;

runtimeDependencies = map lib.getLib [
cups
pango
freetype
gcc-unwrapped.lib
];

autoPatchelfIgnoreMissingDeps = [
Expand All @@ -100,6 +157,12 @@ stdenv.mkDerivation rec {
"libQtCore.so.4"
"libQtNetwork.so.4"
"libQtXml.so.4"
# file manager integration. Not needed
"libnautilus-extension.so.1"
"libcaja-extension.so.1"
"libpeony.so.3"
# libuof.so is a exclusive library in WPS. No need to repatch it
"libuof.so"
];

installPhase = ''
Expand All @@ -116,26 +179,50 @@ stdenv.mkDerivation rec {
substituteInPlace $i \
--replace /usr/bin $out/bin
done
# need system freetype and gcc lib to run properly
for i in wps wpp et wpspdf wpsoffice; do
wrapProgram $out/opt/kingsoft/wps-office/office6/$i \
--set LD_PRELOAD "${freetype}/lib/libfreetype.so" \
--set LD_LIBRARY_PATH "${lib.makeLibraryPath [ gcc-unwrapped.lib ]}"
done
runHook postInstall
'';

preFixup = ''
# The following libraries need libtiff.so.5, but nixpkgs provides libtiff.so.6
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}
patchelf --replace-needed libtiff.so.5 libtiff.so $out/opt/kingsoft/wps-office/office6/addons/ksplitmerge/libksplitmergeapp.so
patchelf --add-needed libtiff.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so
# Fix: Wrong JPEG library version: library is 62, caller expects 80
patchelf --add-needed libjpeg.so $out/opt/kingsoft/wps-office/office6/libwpsmain.so
# dlopen dependency
patchelf --add-needed libudev.so.1 $out/opt/kingsoft/wps-office/office6/addons/cef/libcef.so
# 365 specific: Font watermark
if [ -e $out/opt/kingsoft/wps-office/office6/libFontWatermark.so ]; then
patchelf --replace-needed libmysqlclient.so.18 libmysqlclient.so $out/opt/kingsoft/wps-office/office6/libFontWatermark.so
patchelf --add-rpath "${libmysqlclient}/lib/mariadb" $out/opt/kingsoft/wps-office/office6/libFontWatermark.so
fi
# 365 specific: xiezuo
if [ -e $out/opt/xiezuo/resources/qt-tools/platforminputcontexts/libfcitxplatforminputcontextplugin.so ]; then
patchelf --replace-needed libFcitxQt5DBusAddons.so.1 libFcitx5Qt5DBusAddons.so.1 $out/opt/xiezuo/resources/qt-tools/platforminputcontexts/libfcitxplatforminputcontextplugin.so
fi
'';

meta = with lib; {
description = "Office suite, formerly Kingsoft Office";
homepage = "https://www.wps.com";
platforms = [ "x86_64-linux" ];
platforms = [
"x86_64-linux"
"aarch64-linux"
];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
hydraPlatforms = [ ];
license = licenses.unfreeRedistributable;
maintainers = with maintainers; [ mlatus th0rgal rewine pokon548 ];
maintainers = with maintainers; [
mlatus
th0rgal
rewine
pokon548
];
};
}
9 changes: 9 additions & 0 deletions pkgs/applications/office/wpsoffice/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by ./update.sh - do not update manually!
# Last updated: 2024-11-06
{
version = "12.8.2.18605";
pro_arm64_url = "https://wps-linux-365.wpscdn.cn/wps/download/ep/Linux365/18605/wps-office_12.8.2.18605.AK.preload.sw_arm64.deb";
pro_amd64_url = "https://wps-linux-365.wpscdn.cn/wps/download/ep/Linux365/18605/wps-office_12.8.2.18605.AK.preload.sw_amd64.deb";
pro_arm64_hash = "sha256-BzWpCMzCzn4RFXve7oVd405ErrQLif5wwGdC938oUXw=";
pro_amd64_hash = "sha256-fy238yjdaV6pZOPulAMRJlcj/IHeRDjgMgrTVC0JPLQ=";
}
21 changes: 21 additions & 0 deletions pkgs/applications/office/wpsoffice/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash --pure --keep GITHUB_TOKEN -p nix curl cacert nix-prefetch-git jq

download_json=$(curl 'https://plus.wps.cn/ops/opsd/api/v2/policy' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0' -H 'Accept: application/json' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Content-Type: application/json;charset=utf-8' -H 'Origin: https://365.wps.cn' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://365.wps.cn/' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' -H 'TE: trailers' --data-raw '{"entity_param":[{"window_key":"wps365_download_pc_muti"}]}')
arm64_url=$(echo $download_json | jq '.windows[0].data[3].value | fromjson | .[5].links[0].packageList[0].link' | sed 's/"//g')
amd64_url=$(echo $download_json | jq '.windows[0].data[3].value | fromjson | .[5].links[1].packageList[0].link' | sed 's/"//g')
version=$(echo $amd64_url | awk -F'[_]' '{print $2}' | awk -F'[AK]' '{print $1}' | sed -E 's/(.*)./\1/')
arm64_hash=$(nix hash to-sri --type sha256 "$(nix-prefetch-url $arm64_url)")
amd64_hash=$(nix hash to-sri --type sha256 "$(nix-prefetch-url $amd64_url)")

cat > sources.nix <<EOF
# Generated by ./update.sh - do not update manually!
# Last updated: $(date +%F)
{
version = "$version";
pro_arm64_url = "$arm64_url";
pro_amd64_url = "$amd64_url";
pro_arm64_hash = "$arm64_hash";
pro_amd64_hash = "$amd64_hash";
}
EOF
3 changes: 3 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33248,6 +33248,9 @@ with pkgs;
wpsoffice-cn = libsForQt5.callPackage ../applications/office/wpsoffice {
useChineseVersion = true;
};
wpsoffice-365 = libsForQt5.callPackage ../applications/office/wpsoffice {
use365Version = true;
};

wrapFirefox = callPackage ../applications/networking/browsers/firefox/wrapper.nix { };

Expand Down