lol
1{ stdenv, lib, makeDesktopItem, makeWrapper, config
2
3## various stuff that can be plugged in
4, gnash, flashplayer, hal-flash
5, MPlayerPlugin, gecko_mediaplayer, ffmpeg, gst_all, xorg, libpulseaudio, libcanberra
6, supportsJDK, jrePlugin, icedtea_web
7, trezor-bridge, bluejeans, djview4, adobe-reader
8, google_talk_plugin, fribid, gnome3/*.gnome_shell*/
9, esteidfirefoxplugin
10, vlc_npapi
11}:
12
13## configurability of the wrapper itself
14browser:
15{ browserName ? browser.browserName or (builtins.parseDrvName browser.name).name
16, name ? (browserName + "-" + (builtins.parseDrvName browser.name).version)
17, desktopName ? # browserName with first letter capitalized
18 (lib.toUpper (lib.substring 0 1 browserName) + lib.substring 1 (-1) browserName)
19, nameSuffix ? ""
20, icon ? browserName, libtrick ? true
21}:
22
23let
24 cfg = stdenv.lib.attrByPath [ browserName ] {} config;
25 enableAdobeFlash = cfg.enableAdobeFlash or false;
26 enableGnash = cfg.enableGnash or false;
27 ffmpegSupport = browser.ffmpegSupport or false;
28 jre = cfg.jre or false;
29 icedtea = cfg.icedtea or false;
30
31 plugins =
32 assert !(enableGnash && enableAdobeFlash);
33 assert !(jre && icedtea);
34 ([ ]
35 ++ lib.optional enableGnash gnash
36 ++ lib.optional enableAdobeFlash flashplayer
37 ++ lib.optional (cfg.enableDjvu or false) (djview4)
38 ++ lib.optional (cfg.enableMPlayer or false) (MPlayerPlugin browser)
39 ++ lib.optional (cfg.enableGeckoMediaPlayer or false) gecko_mediaplayer
40 ++ lib.optional (supportsJDK && jre && jrePlugin ? mozillaPlugin) jrePlugin
41 ++ lib.optional icedtea icedtea_web
42 ++ lib.optional (cfg.enableGoogleTalkPlugin or false) google_talk_plugin
43 ++ lib.optional (cfg.enableFriBIDPlugin or false) fribid
44 ++ lib.optional (cfg.enableGnomeExtensions or false) gnome3.gnome_shell
45 ++ lib.optional (cfg.enableTrezor or false) trezor-bridge
46 ++ lib.optional (cfg.enableBluejeans or false) bluejeans
47 ++ lib.optional (cfg.enableAdobeReader or false) adobe-reader
48 ++ lib.optional (cfg.enableEsteid or false) esteidfirefoxplugin
49 ++ lib.optional (cfg.enableVLC or false) vlc_npapi
50 );
51 libs = (if ffmpegSupport then [ ffmpeg ] else with gst_all; [ gstreamer gst-plugins-base ])
52 ++ lib.optionals (cfg.enableQuakeLive or false)
53 (with xorg; [ stdenv.cc libX11 libXxf86dga libXxf86vm libXext libXt alsaLib zlib ])
54 ++ lib.optional (enableAdobeFlash && (cfg.enableAdobeFlashDRM or false)) hal-flash
55 ++ lib.optional (config.pulseaudio or false) libpulseaudio;
56 gst-plugins = with gst_all; [ gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-ffmpeg ];
57 gtk_modules = [ libcanberra ];
58
59in
60stdenv.mkDerivation {
61 inherit name;
62
63 desktopItem = makeDesktopItem {
64 name = browserName;
65 exec = browserName + " %U";
66 inherit icon;
67 comment = "";
68 desktopName = desktopName;
69 genericName = "Web Browser";
70 categories = "Application;Network;WebBrowser;";
71 mimeType = stdenv.lib.concatStringsSep ";" [
72 "text/html"
73 "text/xml"
74 "application/xhtml+xml"
75 "application/vnd.mozilla.xul+xml"
76 "x-scheme-handler/http"
77 "x-scheme-handler/https"
78 "x-scheme-handler/ftp"
79 ];
80 };
81
82 buildInputs = [makeWrapper] ++ lib.optionals (!ffmpegSupport) gst-plugins;
83
84 buildCommand = ''
85 if [ ! -x "${browser}/bin/${browserName}" ]
86 then
87 echo "cannot find executable file \`${browser}/bin/${browserName}'"
88 exit 1
89 fi
90
91 makeWrapper "${browser}/bin/${browserName}" \
92 "$out/bin/${browserName}${nameSuffix}" \
93 --suffix-each MOZ_PLUGIN_PATH ':' "$plugins" \
94 --suffix LD_LIBRARY_PATH ':' "$libs" \
95 --suffix-each GTK_PATH ':' "$gtk_modules" \
96 --suffix-each LD_PRELOAD ':' "$(cat $(filterExisting $(addSuffix /extra-ld-preload $plugins)))" \
97 --prefix-contents PATH ':' "$(filterExisting $(addSuffix /extra-bin-path $plugins))" \
98 --set MOZ_OBJDIR "$(ls -d "${browser}/lib/${browserName}"*)" \
99 ${lib.optionalString (!ffmpegSupport) ''--prefix GST_PLUGIN_SYSTEM_PATH : "$GST_PLUGIN_SYSTEM_PATH"''}
100
101 ${ lib.optionalString libtrick
102 ''
103 libdirname="$(echo "${browser}/lib/${browserName}"*)"
104 libdirbasename="$(basename "$libdirname")"
105 mkdir -p "$out/lib/$libdirbasename"
106 ln -s "$libdirname"/* "$out/lib/$libdirbasename"
107 script_location="$(mktemp "$out/lib/$libdirbasename/${browserName}${nameSuffix}.XXXXXX")"
108 mv "$out/bin/${browserName}${nameSuffix}" "$script_location"
109 ln -s "$script_location" "$out/bin/${browserName}${nameSuffix}"
110 ''
111 }
112
113 if [ -e "${browser}/share/icons" ]; then
114 mkdir -p "$out/share"
115 ln -s "${browser}/share/icons" "$out/share/icons"
116 else
117 mkdir -p "$out/share/icons/hicolor/128x128/apps"
118 ln -s "$out/lib/$libdirbasename/browser/icons/mozicon128.png" \
119 "$out/share/icons/hicolor/128x128/apps/${browserName}.png"
120 fi
121
122 mkdir -p $out/share/applications
123 cp $desktopItem/share/applications/* $out/share/applications
124
125 # For manpages, in case the program supplies them
126 mkdir -p $out/nix-support
127 echo ${browser} > $out/nix-support/propagated-user-env-packages
128 '';
129
130 preferLocalBuild = true;
131
132 # Let each plugin tell us (through its `mozillaPlugin') attribute
133 # where to find the plugin in its tree.
134 plugins = map (x: x + x.mozillaPlugin) plugins;
135 libs = lib.makeLibraryPath libs + ":" + lib.makeSearchPathOutput "lib" "lib64" libs;
136 gtk_modules = map (x: x + x.gtkModule) gtk_modules;
137
138 passthru = { unwrapped = browser; };
139
140 meta = browser.meta // {
141 description =
142 browser.meta.description
143 + " (with plugins: "
144 + lib.concatStrings (lib.intersperse ", " (map (x: x.name) plugins))
145 + ")";
146 hydraPlatforms = [];
147 priority = (browser.meta.priority or 0) - 1; # prefer wrapper over the package
148 };
149}