1{ stdenv, lib, fetchurl, freetype, fontconfig, openssl, unzip }:
2
3let
4 platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" ];
5in
6assert lib.elem stdenv.system platforms;
7
8stdenv.mkDerivation rec {
9 name = "phantomjs-1.9.8";
10
11 # I chose to use the binary build for now.
12 # The source version is quite nasty to compile
13 # because it has bundled a lot of external libraries (like QT and Webkit)
14 # and no easy/nice way to use the system versions of these
15
16 src = if stdenv.system == "i686-linux" then
17 fetchurl {
18 url = "https://bitbucket.org/ariya/phantomjs/downloads/${name}-linux-i686.tar.bz2";
19 sha256 = "11fzmssz9pqf3arh4f36w06sl2nyz8l9h8iyxyd7w5aqnq5la0j1";
20 }
21 else
22 if stdenv.system == "x86_64-linux" then
23 fetchurl {
24 url = "https://bitbucket.org/ariya/phantomjs/downloads/${name}-linux-x86_64.tar.bz2";
25 sha256 = "0fhnqxxsxhy125fmif1lwgnlhfx908spy7fx9mng4w72320n5nd1";
26 }
27 else # x86_64-darwin
28 fetchurl {
29 url = "https://bitbucket.org/ariya/phantomjs/downloads/${name}-macosx.zip";
30 sha256 = "0j0aq8dgzmb210xdrh0v3d4nblskl3zsckl8bzf1a603wcx085cg";
31 };
32
33 buildInputs = lib.optional stdenv.isDarwin unzip;
34
35 buildPhase = lib.optionalString (!stdenv.isDarwin) ''
36 patchelf \
37 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
38 --set-rpath "${stdenv.lib.makeLibraryPath [ freetype fontconfig stdenv.cc.cc stdenv.cc.cc openssl ]}" \
39 bin/phantomjs
40 '';
41
42 dontPatchELF = true;
43 dontStrip = true;
44
45 installPhase = ''
46 mkdir -p $out/share/doc/phantomjs
47 cp -a bin $out
48 cp -a ChangeLog examples LICENSE.BSD README.md third-party.txt $out/share/doc/phantomjs
49 '';
50
51 meta = {
52 description = "Headless WebKit with JavaScript API";
53 longDescription = ''
54 PhantomJS is a headless WebKit with JavaScript API.
55 It has fast and native support for various web standards:
56 DOM handling, CSS selector, JSON, Canvas, and SVG.
57
58 PhantomJS is an optimal solution for:
59 - Headless Website Testing
60 - Screen Capture
61 - Page Automation
62 - Network Monitoring
63 '';
64
65 homepage = http://phantomjs.org/;
66 license = lib.licenses.bsd3;
67
68 maintainers = [ lib.maintainers.bluescreen303 ];
69 inherit platforms;
70 };
71}