about summary refs log tree commit diff
path: root/pkgs/tools/graphics/wkhtmltopdf-bin/default.nix
blob: 29e1d391958f197aa3b8af05be399a71e6307961 (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
{ lib
, autoPatchelfHook
, cpio
, freetype
, zlib
, openssl
, fetchurl
, gcc-unwrapped
, libjpeg8
, libpng
, fontconfig
, stdenv
, xar
, xorg
}:

let
  darwinAttrs = rec {
    version = "0.12.6-2";
    src = fetchurl {
      url = "https://github.com/wkhtmltopdf/packaging/releases/download/${version}/wkhtmltox-${version}.macos-cocoa.pkg";
      sha256 = "sha256-gaZrd7UI/t6NvKpnEnIDdIN2Vos2c6F/ZhG21R6YlPg=";
    };

    nativeBuildInputs = [ xar cpio ];

    unpackPhase = ''
      xar -xf $src
      zcat Payload | cpio -i
      tar -xf usr/local/share/wkhtmltox-installer/wkhtmltox.tar.gz
    '';

    installPhase = ''
      runHook preInstall
      mkdir -p $out
      cp -r bin include lib share $out/
      runHook postInstall
    '';
  };

  linuxAttrs = rec {
    version = "0.12.6-3";
    src = fetchurl {
      url = "https://github.com/wkhtmltopdf/packaging/releases/download/${version}/wkhtmltox-${version}.archlinux-x86_64.pkg.tar.xz";
      sha256 = "sha256-6Ewu8sPRbqvYWj27mBlQYpEN+mb+vKT46ljrdEUxckI=";
    };

    nativeBuildInputs = [ autoPatchelfHook ];

    buildInputs = [
      xorg.libXext
      xorg.libXrender

      freetype
      openssl
      zlib

      (lib.getLib fontconfig)
      (lib.getLib gcc-unwrapped)
      (lib.getLib libjpeg8)
      (lib.getLib libpng)
    ];

    unpackPhase = "tar -xf $src";

    installPhase = ''
      runHook preInstall
      mkdir -p $out
      cp -r usr/bin usr/include usr/lib usr/share $out/
      runHook postInstall
    '';
  };
in
stdenv.mkDerivation ({
  pname = "wkhtmltopdf-bin";

  dontStrip = true;

  doInstallCheck = true;

  installCheckPhase = ''
    $out/bin/wkhtmltopdf --version
  '';

  meta = with lib; {
    homepage = "https://wkhtmltopdf.org/";
    description =
      "Tools for rendering web pages to PDF or images (binary package)";
    longDescription = ''
      wkhtmltopdf and wkhtmltoimage are open source (LGPL) command line tools
      to render HTML into PDF and various image formats using the QT Webkit
      rendering engine. These run entirely "headless" and do not require a
      display or display service.

      There is also a C library, if you're into that kind of thing.
    '';
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [ nbr kalbasit ];
    platforms = [ "x86_64-darwin" "x86_64-linux" ];
  };
}
// lib.optionalAttrs (stdenv.hostPlatform.isDarwin) darwinAttrs
// lib.optionalAttrs (stdenv.hostPlatform.isLinux) linuxAttrs
)