From 39054d17e072acede37b7d625538093b9734cf9d Mon Sep 17 00:00:00 2001 From: Bu Kun <65808665+pokon548@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:54:59 +0800 Subject: [PATCH] wpsoffice-365: init at 12.8.2.18605 --- .../applications/office/wpsoffice/default.nix | 91 ++++++++++++++----- .../applications/office/wpsoffice/sources.nix | 9 ++ pkgs/applications/office/wpsoffice/update.sh | 21 +++++ pkgs/top-level/all-packages.nix | 3 + 4 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 pkgs/applications/office/wpsoffice/sources.nix create mode 100644 pkgs/applications/office/wpsoffice/update.sh diff --git a/pkgs/applications/office/wpsoffice/default.nix b/pkgs/applications/office/wpsoffice/default.nix index f99e4ca92d87a..200b9980cb4f3 100644 --- a/pkgs/applications/office/wpsoffice/default.nix +++ b/pkgs/applications/office/wpsoffice/default.nix @@ -1,4 +1,5 @@ -{ lib, +{ + lib, stdenv, dpkg, autoPatchelfHook, @@ -31,9 +32,12 @@ runCommandLocal, cacert, coreutils, - useChineseVersion ? false + fetchurl, + useChineseVersion ? false, + use365Version ? false, }: let + sources = import ./sources.nix; pkgVersion = "12.1.0.17900"; url = if useChineseVersion then @@ -50,27 +54,55 @@ let 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 = "."; @@ -165,15 +197,32 @@ stdenv.mkDerivation rec { 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 + ]; }; } diff --git a/pkgs/applications/office/wpsoffice/sources.nix b/pkgs/applications/office/wpsoffice/sources.nix new file mode 100644 index 0000000000000..6c7403e7811df --- /dev/null +++ b/pkgs/applications/office/wpsoffice/sources.nix @@ -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="; +} diff --git a/pkgs/applications/office/wpsoffice/update.sh b/pkgs/applications/office/wpsoffice/update.sh new file mode 100644 index 0000000000000..9758c574a3c55 --- /dev/null +++ b/pkgs/applications/office/wpsoffice/update.sh @@ -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 <