nixpkgs/pkgs/applications/networking/browsers/firefox/wrapper.nix

183 lines
7.3 KiB
Nix
Raw Normal View History

{ stdenv, lib, makeDesktopItem, makeWrapper, lndir, config
## various stuff that can be plugged in
, flashplayer, hal-flash
, ffmpeg, xorg, libpulseaudio, libcanberra-gtk2, libglvnd
, gnome3/*.gnome-shell*/
, browserpass, chrome-gnome-shell, uget-integrator, plasma-browser-integration, bukubrow
, tridactyl-native
, fx_cast_bridge
, udev
2017-09-27 13:30:29 +00:00
, kerberos
}:
## configurability of the wrapper itself
2017-11-16 15:39:16 +00:00
browser:
let
2017-11-16 15:39:16 +00:00
wrapper =
{ browserName ? browser.browserName or (lib.getName browser)
, pname ? browserName
, version ? lib.getVersion browser
2017-11-16 15:39:16 +00:00
, desktopName ? # browserName with first letter capitalized
(lib.toUpper (lib.substring 0 1 browserName) + lib.substring 1 (-1) browserName)
, nameSuffix ? ""
, icon ? browserName
, extraNativeMessagingHosts ? []
, gdkWayland ? false
, cfg ? config.${browserName} or {}
2017-11-16 15:39:16 +00:00
}:
assert gdkWayland -> (browser ? gtk3); # Can only use the wayland backend if gtk3 is being used
2017-11-16 15:39:16 +00:00
let
enableAdobeFlash = cfg.enableAdobeFlash or false;
ffmpegSupport = browser.ffmpegSupport or false;
gssSupport = browser.gssSupport or false;
plugins =
let
removed = lib.filter (a: builtins.hasAttr a cfg) [
"enableVLC"
"enableDjvu"
"enableMPlayer"
"jre"
"icedtea"
"enableGoogleTalkPlugin"
"enableFriBIDPlugin"
"enableBluejeans"
"enableAdobeReader"
];
in if removed != []
then throw "Your configuration mentions ${lib.concatMapStringsSep ", " (p: browserName + "." + p) removed}. All plugin related options, except for the adobe flash player, have been removed, since Firefox from version 52 onwards no longer supports npapi plugins (see https://support.mozilla.org/en-US/kb/npapi-plugins)."
else lib.optional enableAdobeFlash flashplayer;
2017-11-16 15:39:16 +00:00
nativeMessagingHosts =
([ ]
++ lib.optional (cfg.enableBrowserpass or false) (lib.getBin browserpass)
++ lib.optional (cfg.enableBukubrow or false) bukubrow
++ lib.optional (cfg.enableTridactylNative or false) tridactyl-native
++ lib.optional (cfg.enableGnomeExtensions or false) chrome-gnome-shell
2018-04-30 02:41:36 +00:00
++ lib.optional (cfg.enableUgetIntegrator or false) uget-integrator
++ lib.optional (cfg.enablePlasmaBrowserIntegration or false) plasma-browser-integration
++ lib.optional (cfg.enableFXCastBridge or false) fx_cast_bridge
++ extraNativeMessagingHosts
2017-11-16 15:39:16 +00:00
);
libs = lib.optional stdenv.isLinux udev
2018-06-25 01:49:30 +00:00
++ lib.optional ffmpegSupport ffmpeg
2017-11-16 15:39:16 +00:00
++ lib.optional gssSupport kerberos
++ lib.optional gdkWayland libglvnd
2017-11-16 15:39:16 +00:00
++ lib.optionals (cfg.enableQuakeLive or false)
2018-06-25 01:49:30 +00:00
(with xorg; [ stdenv.cc libX11 libXxf86dga libXxf86vm libXext libXt alsaLib zlib ])
2017-11-16 15:39:16 +00:00
++ lib.optional (enableAdobeFlash && (cfg.enableAdobeFlashDRM or false)) hal-flash
++ lib.optional (config.pulseaudio or true) libpulseaudio;
gtk_modules = [ libcanberra-gtk2 ];
2017-11-16 15:39:16 +00:00
in stdenv.mkDerivation {
inherit pname version;
2017-11-16 15:39:16 +00:00
desktopItem = makeDesktopItem {
name = browserName;
exec = "${browserName}${nameSuffix} %U";
inherit icon;
comment = "";
desktopName = "${desktopName}${nameSuffix}${lib.optionalString gdkWayland " (Wayland)"}";
2017-11-16 15:39:16 +00:00
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"
];
};
nativeBuildInputs = [ makeWrapper lndir ];
buildInputs = lib.optional (browser ? gtk3) browser.gtk3;
2017-11-16 15:39:16 +00:00
buildCommand = lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
cp -R --no-preserve=mode,ownership ${browser}/Applications/${browserName}.app $out/Applications
rm -f $out${browser.execdir or "/bin"}/${browserName}
'' + ''
if [ ! -x "${browser}${browser.execdir or "/bin"}/${browserName}" ]
2017-11-16 15:39:16 +00:00
then
echo "cannot find executable file \`${browser}${browser.execdir or "/bin"}/${browserName}'"
2017-11-16 15:39:16 +00:00
exit 1
fi
makeWrapper "$(readlink -v --canonicalize-existing "${browser}${browser.execdir or "/bin"}/${browserName}")" \
"$out${browser.execdir or "/bin"}/${browserName}${nameSuffix}" \
2017-11-16 15:39:16 +00:00
--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))" \
--suffix PATH ':' "$out${browser.execdir or "/bin"}" \
2017-11-16 15:39:16 +00:00
--set MOZ_APP_LAUNCHER "${browserName}${nameSuffix}" \
--set MOZ_SYSTEM_DIR "$out/lib/mozilla" \
--set SNAP_NAME "firefox" \
--set MOZ_LEGACY_PROFILES 1 \
--set MOZ_ALLOW_DOWNGRADE 1 \
${lib.optionalString gdkWayland ''
--set GDK_BACKEND "wayland" \
''}${lib.optionalString (browser ? gtk3)
2017-11-16 15:39:16 +00:00
''--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH" \
2019-02-13 21:47:50 +00:00
--suffix XDG_DATA_DIRS : '${gnome3.adwaita-icon-theme}/share'
2017-11-16 15:39:16 +00:00
''
}
if [ -e "${browser}/share/icons" ]; then
mkdir -p "$out/share"
ln -s "${browser}/share/icons" "$out/share/icons"
else
for res in 16 32 48 64 128; do
mkdir -p "$out/share/icons/hicolor/''${res}x''${res}/apps"
icon=( "${browser}/lib/"*"/browser/chrome/icons/default/default''${res}.png" )
if [ -e "$icon" ]; then ln -s "$icon" \
"$out/share/icons/hicolor/''${res}x''${res}/apps/${browserName}.png"
fi
done
2017-11-16 15:39:16 +00:00
fi
install -D -t $out/share/applications $desktopItem/share/applications/*
mkdir -p $out/lib/mozilla/native-messaging-hosts
2017-11-16 15:39:16 +00:00
for ext in ${toString nativeMessagingHosts}; do
ln -sLt $out/lib/mozilla/native-messaging-hosts $ext/lib/mozilla/native-messaging-hosts/*
2017-11-16 15:39:16 +00:00
done
# 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; };
disallowedRequisites = [ stdenv.cc ];
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
};
};
in
lib.makeOverridable wrapper