@@ -0,0 +1,120 @@
1+{ stdenv, buildEnv, fetchurl, patchelf, bash
2+
3+# Linked dynamic libraries.
4+, glib, fontconfig, freetype, pango, cairo, libX11, libXi, atk, gconf, nss, nspr
5+, libXcursor, libXext, libXfixes, libXrender, libXScrnSaver, libXcomposite
6+, alsaLib, libXdamage, libXtst, libXrandr, expat, cups
7+, dbus_libs, gtk, gdk_pixbuf, gcc
8+
9+# Will crash without.
10+, udev
11+
12+# Loaded at runtime.
13+, libexif
14+
15+# Additional dependencies according to other distros.
16+## Ubuntu
17+, liberation_ttf, curl, utillinux, xdg_utils, wget
18+## Arch Linux.
19+, flac, harfbuzz, icu, libpng, libopus, snappy, speechd
20+## Gentoo
21+, bzip2, libcap
22+
23+# Which distribution channel to use.
24+, channel ? "stable"
25+
26+# Necessary for USB audio devices.
27+, pulseSupport ? true, libpulseaudio ? null
28+
29+}:
30+
31+with stdenv.lib;
32+
33+with (import ../chromium/source/update.nix {
34+ inherit (stdenv) system;
35+}).getChannel channel;
36+
37+let
38+ dist = if channel == "dev" then "unstable" else channel;
39+
40+ opusWithCustomModes = libopus.override {
41+ withCustomModes = true;
42+ };
43+
44+ env = buildEnv {
45+ name = "google-chrome-env";
46+ paths = [
47+ glib fontconfig freetype pango cairo libX11 libXi atk gconf nss nspr
48+ libXcursor libXext libXfixes libXrender libXScrnSaver libXcomposite
49+ alsaLib libXdamage libXtst libXrandr expat cups
50+ dbus_libs gtk gdk_pixbuf gcc
51+ udev
52+ libexif
53+ liberation_ttf curl utillinux xdg_utils wget
54+ flac harfbuzz icu libpng opusWithCustomModes snappy speechd
55+ bzip2 libcap
56+ ]
57+ ++ optional pulseSupport libpulseaudio;
58+ };
59+in stdenv.mkDerivation rec {
60+ inherit version;
61+
62+ name = "google-chrome-${version}";
63+
64+ src = fetchurl binary;
65+
66+ buildInputs = [ env patchelf ];
67+
68+ unpackPhase = ''
69+ ar x $src
70+ tar xf data.tar.xz
71+ '';
72+
73+ installPhase = ''
74+ exe=$out/bin/google-chrome-${dist}
75+ rpath="${env}/lib:${env}/lib64"
76+
77+ mkdir -p $out/bin $out/share
78+
79+ cp -a opt/* $out/share
80+ cp -a usr/share/* $out/share
81+
82+ substituteInPlace $out/share/applications/google-chrome.desktop \
83+ --replace /usr/bin/google-chrome-${dist} $exe
84+ substituteInPlace $out/share/gnome-control-center/default-apps/google-chrome.xml \
85+ --replace /opt/google/chrome/google-chrome $exe
86+ substituteInPlace $out/share/menu/google-chrome.menu \
87+ --replace /opt $out/share \
88+ --replace $out/share/google/chrome/google-chrome $exe
89+
90+ for icon_file in $out/share/google/chrome/product_logo_*[0-9].png; do
91+ num_and_suffix="''${icon_file##*logo_}"
92+ icon_size="''${num_and_suffix%.*}"
93+ logo_output_prefix="$out/share/icons/hicolor"
94+ logo_output_path="$logo_output_prefix/''${icon_size}x''${icon_size}/apps"
95+ mkdir -p "$logo_output_path"
96+ mv "$icon_file" "$logo_output_path/google-chrome.png"
97+ done
98+
99+ cat > $exe << EOF
100+ #!${bash}/bin/sh
101+ export LD_LIBRARY_PATH=$rpath\''${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}
102+ export PATH=${env}/bin\''${PATH:+:\$PATH}
103+ $out/share/google/chrome/google-chrome "\$@"
104+ EOF
105+ chmod +x $exe
106+
107+ for elf in $out/share/google/chrome/{chrome,chrome-sandbox,nacl_helper}; do
108+ patchelf --set-rpath $rpath $elf
109+ patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $elf
110+ done
111+ '';
112+
113+ meta = {
114+ description = "A freeware web browser developed by Google";
115+ homepage = "https://www.google.com/chrome/browser/";
116+ license = licenses.unfree;
117+ maintainers = [ maintainers.msteen ];
118+ platforms = platforms.linux;
119+ };
120+}