aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/applications/office/softmaker/generic.nix
blob: fbde26058e1bf1638166c7befdd4f3cefad1df4c (plain)
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
{ stdenv, fetchurl, autoPatchelfHook, makeDesktopItem, makeWrapper, copyDesktopItems

  # Dynamic Libraries
, curl, libGL, libX11, libXext, libXmu, libXrandr, libXrender

  # For fixing up execution of /bin/ls, which is necessary for
  # product unlocking.
, coreutils, libredirect

  # Extra utilities used by the SoftMaker applications.
, gnugrep, util-linux, which

, pname, version, edition, suiteName, src, archive

, ...
}:

let
  desktopItems = import ./desktop_items.nix {
    inherit makeDesktopItem pname suiteName;
  };
  shortEdition = builtins.substring 2 2 edition;
in stdenv.mkDerivation {
  inherit pname src;

  version = "${edition}.${version}";

  nativeBuildInputs = [
    autoPatchelfHook
    copyDesktopItems
    makeWrapper
  ];

  buildInputs = [
    curl
    libGL
    libX11
    libXext
    libXmu
    libXrandr
    libXrender
    stdenv.cc.cc.lib
  ];

  dontBuild = true;
  dontConfigure = true;

  unpackPhase = ''
    runHook preUnpack

    mkdir installer
    tar -C installer -xf ${src}
    mkdir ${pname}
    tar -C ${pname} -xf installer/${archive}

    runHook postUnpack
  '';

  installPhase = let
    # SoftMaker/FreeOffice collects some system information upon
    # unlocking the product. But in doing so, it attempts to execute
    # /bin/ls. If the execve syscall fails, the whole unlock
    # procedure fails. This works around that by rewriting /bin/ls
    # to the proper path.
    #
    # In addition, it expects some common utilities (which, whereis)
    # to be in the path.
    #
    # SoftMaker Office restarts itself upon some operations, such
    # changing the theme and unlocking. Unfortunately, we do not
    # have control over its environment then and it will fail
    # with an error.
    extraWrapperArgs = ''
      --set LD_PRELOAD "${libredirect}/lib/libredirect.so" \
      --set NIX_REDIRECTS "/bin/ls=${coreutils}/bin/ls" \
      --prefix PATH : "${stdenv.lib.makeBinPath [ coreutils gnugrep util-linux which ]}"
    '';
  in ''
    runHook preInstall

    mkdir -p $out/share
    cp -r ${pname} $out/share/${pname}${edition}

    # Wrap rather than symlinking, so that the programs can determine
    # their resource path.
    mkdir -p $out/bin
    makeWrapper $out/share/${pname}${edition}/planmaker $out/bin/${pname}-planmaker \
      ${extraWrapperArgs}
    makeWrapper $out/share/${pname}${edition}/presentations $out/bin/${pname}-presentations \
      ${extraWrapperArgs}
    makeWrapper $out/share/${pname}${edition}/textmaker $out/bin/${pname}-textmaker \
      ${extraWrapperArgs}

    for size in 16 32 48 64 96 128 256 512 1024; do
      mkdir -p $out/share/icons/hicolor/''${size}x''${size}/apps

      for app in pml prl tml; do
        ln -s $out/share/${pname}${edition}/icons/''${app}_''${size}.png \
          $out/share/icons/hicolor/''${size}x''${size}/apps/${pname}-''${app}.png
      done

      mkdir -p $out/share/icons/hicolor/''${size}x''${size}/mimetypes

      for mimetype in pmd prd tmd; do
        ln -s $out/share/${pname}${edition}/icons/''${mimetype}_''${size}.png \
          $out/share/icons/hicolor/''${size}x''${size}/mimetypes/application-x-''${mimetype}.png
      done
    done

    # freeoffice 973 misses the 96x96 application icons, giving broken symbolic links
    # remove broken symbolic links
    find $out -xtype l -ls -exec rm {} \;

    # Add mime types
    install -D -t $out/share/mime/packages ${pname}/mime/softmaker-*office*${shortEdition}.xml

    runHook postInstall
  '';

  desktopItems = builtins.attrValues desktopItems;

  meta = with stdenv.lib; {
    description = "An office suite with a word processor, spreadsheet and presentation program";
    homepage = "https://www.softmaker.com/";
    license = licenses.unfree;
    maintainers = with maintainers; [ danieldk ];
    platforms = [ "x86_64-linux" ];
  };
}