summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers/firefox/wrapper.nix
blob: 4da73326177493a732f7f6f98d9554ca7923a994 (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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{ stdenv, lib, makeDesktopItem, makeWrapper, config

## various stuff that can be plugged in
, gnash, flashplayer, hal-flash
, MPlayerPlugin, gecko_mediaplayer, ffmpeg, gst_all, xorg, libpulseaudio, libcanberra_gtk2
, supportsJDK, jrePlugin, icedtea_web
, trezor-bridge, bluejeans, djview4, adobe-reader
, google_talk_plugin, fribid, gnome3/*.gnome_shell*/
, esteidfirefoxplugin
, vlc_npapi
}:

## configurability of the wrapper itself
browser:
{ browserName ? browser.browserName or (builtins.parseDrvName browser.name).name
, name ? (browserName + "-" + (builtins.parseDrvName browser.name).version)
, desktopName ? # browserName with first letter capitalized
  (lib.toUpper (lib.substring 0 1 browserName) + lib.substring 1 (-1) browserName)
, nameSuffix ? ""
, icon ? browserName, libtrick ? true
}:

let
  cfg = stdenv.lib.attrByPath [ browserName ] {} config;
  enableAdobeFlash = cfg.enableAdobeFlash or false;
  enableGnash = cfg.enableGnash or false;
  ffmpegSupport = browser.ffmpegSupport or false;
  jre = cfg.jre or false;
  icedtea = cfg.icedtea or false;

  plugins =
     assert !(enableGnash && enableAdobeFlash);
     assert !(jre && icedtea);
     ([ ]
      ++ lib.optional enableGnash gnash
      ++ lib.optional enableAdobeFlash flashplayer
      ++ lib.optional (cfg.enableDjvu or false) (djview4)
      ++ lib.optional (cfg.enableMPlayer or false) (MPlayerPlugin browser)
      ++ lib.optional (cfg.enableGeckoMediaPlayer or false) gecko_mediaplayer
      ++ lib.optional (supportsJDK && jre && jrePlugin ? mozillaPlugin) jrePlugin
      ++ lib.optional icedtea icedtea_web
      ++ lib.optional (cfg.enableGoogleTalkPlugin or false) google_talk_plugin
      ++ lib.optional (cfg.enableFriBIDPlugin or false) fribid
      ++ lib.optional (cfg.enableGnomeExtensions or false) gnome3.gnome_shell
      ++ lib.optional (cfg.enableTrezor or false) trezor-bridge
      ++ lib.optional (cfg.enableBluejeans or false) bluejeans
      ++ lib.optional (cfg.enableAdobeReader or false) adobe-reader
      ++ lib.optional (cfg.enableEsteid or false) esteidfirefoxplugin
      ++ lib.optional (cfg.enableVLC or false) vlc_npapi
     );
  libs = (if ffmpegSupport then [ ffmpeg ] else with gst_all; [ gstreamer gst-plugins-base ])
         ++ lib.optionals (cfg.enableQuakeLive or false)
         (with xorg; [ stdenv.cc libX11 libXxf86dga libXxf86vm libXext libXt alsaLib zlib ])
         ++ lib.optional (enableAdobeFlash && (cfg.enableAdobeFlashDRM or false)) hal-flash
         ++ lib.optional (config.pulseaudio or false) libpulseaudio;
  gst-plugins = with gst_all; [ gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-ffmpeg ];
  gtk_modules = [ libcanberra_gtk2 ];

in
stdenv.mkDerivation {
  inherit name;

  desktopItem = makeDesktopItem {
    name = browserName;
    exec = browserName + " %U";
    inherit icon;
    comment = "";
    desktopName = desktopName;
    genericName = "Web Browser";
    categories = "Application;Network;WebBrowser;";
    mimeType = stdenv.lib.concatStringsSep ";" [
      "text/html"
      "text/xml"
      "application/xhtml+xml"
      "application/vnd.mozilla.xul+xml"
      "x-scheme-handler/http"
      "x-scheme-handler/https"
      "x-scheme-handler/ftp"
    ];
  };

  buildInputs = [makeWrapper] ++ lib.optionals (!ffmpegSupport) gst-plugins;

  buildCommand = ''
    if [ ! -x "${browser}/bin/${browserName}" ]
    then
        echo "cannot find executable file \`${browser}/bin/${browserName}'"
        exit 1
    fi

    makeWrapper "${browser}/bin/${browserName}" \
        "$out/bin/${browserName}${nameSuffix}" \
        --suffix-each MOZ_PLUGIN_PATH ':' "$plugins" \
        --suffix LD_LIBRARY_PATH ':' "$libs" \
        --suffix-each GTK_PATH ':' "$gtk_modules" \
        --suffix-each LD_PRELOAD ':' "$(cat $(filterExisting $(addSuffix /extra-ld-preload $plugins)))" \
        --prefix-contents PATH ':' "$(filterExisting $(addSuffix /extra-bin-path $plugins))" \
        --set MOZ_OBJDIR "$(ls -d "${browser}/lib/${browserName}"*)" \
        ${lib.optionalString (!ffmpegSupport) ''--prefix GST_PLUGIN_SYSTEM_PATH : "$GST_PLUGIN_SYSTEM_PATH"''}

    ${ lib.optionalString libtrick
    ''
    libdirname="$(echo "${browser}/lib/${browserName}"*)"
    libdirbasename="$(basename "$libdirname")"
    mkdir -p "$out/lib/$libdirbasename"
    ln -s "$libdirname"/* "$out/lib/$libdirbasename"
    script_location="$(mktemp "$out/lib/$libdirbasename/${browserName}${nameSuffix}.XXXXXX")"
    mv "$out/bin/${browserName}${nameSuffix}" "$script_location"
    ln -s "$script_location" "$out/bin/${browserName}${nameSuffix}"
    ''
    }

    if [ -e "${browser}/share/icons" ]; then
        mkdir -p "$out/share"
        ln -s "${browser}/share/icons" "$out/share/icons"
    else
        mkdir -p "$out/share/icons/hicolor/128x128/apps"
        ln -s "$out/lib/$libdirbasename/browser/icons/mozicon128.png" \
            "$out/share/icons/hicolor/128x128/apps/${browserName}.png"
    fi

    mkdir -p $out/share/applications
    cp $desktopItem/share/applications/* $out/share/applications

    # For manpages, in case the program supplies them
    mkdir -p $out/nix-support
    echo ${browser} > $out/nix-support/propagated-user-env-packages
  '';

  preferLocalBuild = true;

  # Let each plugin tell us (through its `mozillaPlugin') attribute
  # where to find the plugin in its tree.
  plugins = map (x: x + x.mozillaPlugin) plugins;
  libs = lib.makeLibraryPath libs + ":" + lib.makeSearchPathOutput "lib" "lib64" libs;
  gtk_modules = map (x: x + x.gtkModule) gtk_modules;

  passthru = { unwrapped = browser; };

  meta = browser.meta // {
    description =
      browser.meta.description
      + " (with plugins: "
      + lib.concatStrings (lib.intersperse ", " (map (x: x.name) plugins))
      + ")";
    hydraPlatforms = [];
    priority = (browser.meta.priority or 0) - 1; # prefer wrapper over the package
  };
}