about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/office/wpsoffice/default.nix
blob: 2d8f4d18621c1f379824eba0143622bc21f3c571 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
{ stdenv
, mkDerivation
, fetchurl
, autoPatchelfHook
, dpkg
, wrapGAppsHook
, wrapQtAppsHook
, alsaLib
, atk
, bzip2
, cairo
, cups
, dbus
, expat
, ffmpeg_3
, fontconfig
, freetype
, gdk-pixbuf
, glib
, gperftools
, gtk2-x11
, libpng12
, libtool
, libuuid
, libxml2
, lzma
, nspr
, nss
, openssl
, pango
, qt4
, qtbase
, sqlite
, unixODBC
, xorg
, zlib
}:

stdenv.mkDerivation rec{
  pname = "wpsoffice";
  version = "11.1.0.9505";

  src = fetchurl {
    url = "http://wdl1.pcfg.cache.wpscdn.com/wpsdl/wpsoffice/download/linux/9505/wps-office_11.1.0.9505.XA_amd64.deb";
    sha256 = "1bvaxwd3npw3kswk7k1p6mcbfg37x0ym4sp6xis6ykz870qivqk5";
  };
  unpackCmd = "dpkg -x $src .";
  sourceRoot = ".";

  postUnpack = stdenv.lib.optionalString (version == "11.1.0.9505") ''
    # distribution is missing libjsapiservice.so, so we should not let
    # autoPatchelfHook fail on the following dead libraries
    rm opt/kingsoft/wps-office/office6/{libjsetapi.so,libjswppapi.so,libjswpsapi.so}
  '';

  nativeBuildInputs = [ autoPatchelfHook dpkg wrapGAppsHook wrapQtAppsHook ];

  meta = {
    description = "Office program originally named Kingsoft Office";
    homepage = "http://wps-community.org/";
    platforms = [ "x86_64-linux" ];
    hydraPlatforms = [];
    license = stdenv.lib.licenses.unfreeRedistributable;
    maintainers = [ stdenv.lib.maintainers.mlatus ];
  };

  buildInputs = with xorg; [
    alsaLib
    atk
    bzip2
    cairo
    dbus.lib
    expat
    ffmpeg_3
    fontconfig
    freetype
    gdk-pixbuf
    glib
    gperftools
    gtk2-x11
    libICE
    libSM
    libX11
    libX11
    libXScrnSaver
    libXcomposite
    libXcursor
    libXdamage
    libXext
    libXfixes
    libXi
    libXrandr
    libXrender
    libXtst
    libpng12
    libtool
    libuuid
    libxcb
    libxml2
    lzma
    nspr
    nss
    openssl
    pango
    qt4
    qtbase
    sqlite
    unixODBC
    zlib
  ];

  dontPatchELF = true;

  # wpsoffice uses `/build` in its own build system making nix things there
  # references to nix own build directory
  noAuditTmpdir = true;

  unvendoredLibraries = [
    # Have to use parts of the vendored qt4
    #"Qt"
    "SDL2"
    "bz2"
    "avcodec"
    "avdevice"
    "avformat"
    "avutil"
    "swresample"
    "swscale"
    "jpeg"
    "png"
    # File saving breaks unless we are using vendored llvmPackages_8.libcxx
    #"c++"
    "ssl" "crypto"
    "nspr"
    "nss"
    "odbc"
    "tcmalloc" # gperftools
  ];

  installPhase = ''
    prefix=$out/opt/kingsoft/wps-office
    mkdir -p $out
    cp -r opt $out
    cp -r usr/* $out
    for lib in $unvendoredLibraries; do
      rm -v "$prefix/office6/lib$lib"*.so{,.*}
    done
    for i in wps wpp et wpspdf; do
      substituteInPlace $out/bin/$i \
        --replace /opt/kingsoft/wps-office $prefix
    done
    for i in $out/share/applications/*;do
      substituteInPlace $i \
        --replace /usr/bin $out/bin
    done
  '';

  runtimeLibPath = stdenv.lib.makeLibraryPath [
    cups.lib
  ];

  dontWrapQtApps = true;
  dontWrapGApps = true;
  postFixup = ''
    for f in "$out"/bin/*; do
      echo "Wrapping $f"
      wrapProgram "$f" \
        "''${gappsWrapperArgs[@]}" \
        "''${qtWrapperArgs[@]}" \
        --suffix LD_LIBRARY_PATH : "$runtimeLibPath"
    done
  '';
}