firefox: simplify derivation

with firefox 64 being the latest version, and the removal of
"tor-browser/icecat-like" variants, we can greatly simplify the common
firefox derivation.
This commit is contained in:
Florian Klink 2020-02-01 18:56:13 +01:00
parent e3659c50fc
commit 94b2596540

View File

@ -1,8 +1,6 @@
{ pname, ffversion, meta, updateScript ? null { pname, ffversion, meta, updateScript ? null
, src, unpackPhase ? null, patches ? [] , src, unpackPhase ? null, patches ? []
, extraNativeBuildInputs ? [], extraConfigureFlags ? [], extraMakeFlags ? [] , extraNativeBuildInputs ? [], extraConfigureFlags ? [], extraMakeFlags ? [] }:
, isIceCatLike ? false, icversion ? null
, isTorBrowserLike ? false, tbversion ? null }:
{ lib, stdenv, pkgconfig, pango, perl, python2, python3, zip, libIDL { lib, stdenv, pkgconfig, pango, perl, python2, python3, zip, libIDL
, libjpeg, zlib, dbus, dbus-glib, bzip2, xorg , libjpeg, zlib, dbus, dbus-glib, bzip2, xorg
@ -27,16 +25,14 @@
## privacy-related options ## privacy-related options
, privacySupport ? isTorBrowserLike || isIceCatLike , privacySupport ? false
# WARNING: NEVER set any of the options below to `true` by default. # WARNING: NEVER set any of the options below to `true` by default.
# Set to `!privacySupport` or `false`. # Set to `!privacySupport` or `false`.
# webrtcSupport breaks the aarch64 build on version >= 60, fixed in 63. # webrtcSupport breaks the aarch64 build on version >= 60, fixed in 63.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1434589 # https://bugzilla.mozilla.org/show_bug.cgi?id=1434589
, webrtcSupport ? !privacySupport && (!stdenv.isAarch64 || !( , webrtcSupport ? !privacySupport
lib.versionAtLeast ffversion "60" && lib.versionOlder ffversion "63"
))
, geolocationSupport ? !privacySupport , geolocationSupport ? !privacySupport
, googleAPISupport ? geolocationSupport , googleAPISupport ? geolocationSupport
, crashreporterSupport ? false , crashreporterSupport ? false
@ -79,7 +75,7 @@ let
default-toolkit = if stdenv.isDarwin then "cairo-cocoa" default-toolkit = if stdenv.isDarwin then "cairo-cocoa"
else "cairo-gtk${if gtk3Support then "3${lib.optionalString waylandSupport "-wayland"}" else "2"}"; else "cairo-gtk${if gtk3Support then "3${lib.optionalString waylandSupport "-wayland"}" else "2"}";
binaryName = if isIceCatLike then "icecat" else "firefox"; binaryName = "firefox";
binaryNameCapitalized = lib.toUpper (lib.substring 0 1 binaryName) + lib.substring 1 (-1) binaryName; binaryNameCapitalized = lib.toUpper (lib.substring 0 1 binaryName) + lib.substring 1 (-1) binaryName;
browserName = if stdenv.isDarwin then binaryNameCapitalized else binaryName; browserName = if stdenv.isDarwin then binaryNameCapitalized else binaryName;
@ -87,21 +83,17 @@ let
execdir = if stdenv.isDarwin execdir = if stdenv.isDarwin
then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS" then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS"
else "/bin"; else "/bin";
in
browserVersion = if isIceCatLike then icversion stdenv.mkDerivation ({
else if isTorBrowserLike then tbversion name = "${pname}-unwrapped-${ffversion}";
else ffversion; version = ffversion;
browserPatches = [ inherit src unpackPhase meta;
patches = [
./env_var_for_system_dir.patch ./env_var_for_system_dir.patch
] ] ++ lib.optionals (stdenv.isAarch64) [
++ lib.optional (lib.versionAtLeast ffversion "63" && lib.versionOlder ffversion "68.3.0")
(fetchpatch { # https://bugzilla.mozilla.org/show_bug.cgi?id=1500436#c29
name = "write_error-parallel_make.diff";
url = "https://hg.mozilla.org/mozilla-central/raw-diff/562655fe/python/mozbuild/mozbuild/action/node.py";
sha256 = "11d7rgzinb4mwl7yzhidjkajynmxgmffr4l9isgskfapyax9p88y";
})
++ lib.optionals (stdenv.isAarch64 && lib.versionAtLeast ffversion "66" && lib.versionOlder ffversion "67") [
(fetchpatch { (fetchpatch {
url = "https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/09c7fa0dc1d87922e3b464c0fa084df1227fca79/extra/firefox/arm.patch"; url = "https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/09c7fa0dc1d87922e3b464c0fa084df1227fca79/extra/firefox/arm.patch";
sha256 = "1vbpih23imhv5r3g21m3m541z08n9n9j1nvmqax76bmyhn7mxp32"; sha256 = "1vbpih23imhv5r3g21m3m541z08n9n9j1nvmqax76bmyhn7mxp32";
@ -117,15 +109,6 @@ let
}) })
++ patches; ++ patches;
in
stdenv.mkDerivation (rec {
name = "${pname}-unwrapped-${version}";
version = browserVersion;
inherit src unpackPhase meta;
patches = browserPatches;
# Ignore trivial whitespace changes in patches, this fixes compatibility of # Ignore trivial whitespace changes in patches, this fixes compatibility of
# ./env_var_for_system_dir.patch with Firefox >=65 without having to track # ./env_var_for_system_dir.patch with Firefox >=65 without having to track
@ -141,16 +124,14 @@ stdenv.mkDerivation (rec {
xorg.libXext sqlite unzip makeWrapper xorg.libXext sqlite unzip makeWrapper
libevent libstartup_notification libvpx /* cairo */ libevent libstartup_notification libvpx /* cairo */
icu libpng jemalloc glib icu libpng jemalloc glib
] nasm
++ lib.optionals (!isTorBrowserLike) [ nspr nss ]
++ lib.optional (lib.versionOlder ffversion "53") libXdamage
++ lib.optional (lib.versionOlder ffversion "61") hunspell
# >= 66 requires nasm for the AV1 lib dav1d # >= 66 requires nasm for the AV1 lib dav1d
# yasm can potentially be removed in future versions # yasm can potentially be removed in future versions
# https://bugzilla.mozilla.org/show_bug.cgi?id=1501796 # https://bugzilla.mozilla.org/show_bug.cgi?id=1501796
# https://groups.google.com/forum/#!msg/mozilla.dev.platform/o-8levmLU80/SM_zQvfzCQAJ # https://groups.google.com/forum/#!msg/mozilla.dev.platform/o-8levmLU80/SM_zQvfzCQAJ
++ lib.optional (lib.versionAtLeast ffversion "66") nasm nspr nss
]
++ lib.optional alsaSupport alsaLib ++ lib.optional alsaSupport alsaLib
++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed ++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed
++ lib.optional gtk3Support gtk3 ++ lib.optional gtk3Support gtk3
@ -162,27 +143,33 @@ stdenv.mkDerivation (rec {
NIX_CFLAGS_COMPILE = toString ([ NIX_CFLAGS_COMPILE = toString ([
"-I${glib.dev}/include/gio-unix-2.0" "-I${glib.dev}/include/gio-unix-2.0"
]
++ lib.optionals (!isTorBrowserLike) [
"-I${nss.dev}/include/nss" "-I${nss.dev}/include/nss"
] ]
++ lib.optional (pname == "firefox-esr" && lib.versionAtLeast ffversion "68" ++ lib.optional (pname == "firefox-esr" && lib.versionOlder ffversion "69")
&& lib.versionOlder ffversion "69")
"-Wno-error=format-security"); "-Wno-error=format-security");
postPatch = lib.optionalString (lib.versionAtLeast ffversion "63.0" && !isTorBrowserLike) '' postPatch = ''
substituteInPlace third_party/prio/prio/rand.c --replace 'nspr/prinit.h' 'prinit.h' substituteInPlace third_party/prio/prio/rand.c --replace 'nspr/prinit.h' 'prinit.h'
'' + lib.optionalString (lib.versionAtLeast ffversion "68") ''
rm -rf obj-x86_64-pc-linux-gnu rm -rf obj-x86_64-pc-linux-gnu
''; '';
nativeBuildInputs = nativeBuildInputs =
[ autoconf213 which gnused pkgconfig perl python2 cargo rustc ] [
autoconf213
cargo
gnused
llvmPackages.llvm # llvm-objdump
nodejs
perl
pkgconfig
python2
python3
rust-cbindgen
rustc
which
]
++ lib.optional gtk3Support wrapGAppsHook ++ lib.optional gtk3Support wrapGAppsHook
++ lib.optionals stdenv.isDarwin [ xcbuild rsync ] ++ lib.optionals stdenv.isDarwin [ xcbuild rsync ]
++ lib.optional (lib.versionAtLeast ffversion "61.0") python3
++ lib.optionals (lib.versionAtLeast ffversion "63.0") [ rust-cbindgen nodejs ]
++ lib.optionals (lib.versionAtLeast ffversion "67.0") [ llvmPackages.llvm ] # llvm-objdump is required in version >=67.0
++ extraNativeBuildInputs; ++ extraNativeBuildInputs;
preConfigure = '' preConfigure = ''
@ -190,14 +177,8 @@ stdenv.mkDerivation (rec {
rm -f configure rm -f configure
rm -f js/src/configure rm -f js/src/configure
rm -f .mozconfig* rm -f .mozconfig*
'' + (if lib.versionAtLeast ffversion "58"
# this will run autoconf213 # this will run autoconf213
then ''
configureScript="$(realpath ./mach) configure" configureScript="$(realpath ./mach) configure"
'' else ''
make -f client.mk configure-files
configureScript="$(realpath ./configure)"
'') + lib.optionalString (lib.versionAtLeast ffversion "53") ''
export MOZCONFIG=$(pwd)/mozconfig export MOZCONFIG=$(pwd)/mozconfig
# Set C flags for Rust's bindgen program. Unlike ordinary C # Set C flags for Rust's bindgen program. Unlike ordinary C
@ -214,23 +195,16 @@ stdenv.mkDerivation (rec {
$NIX_CFLAGS_COMPILE" $NIX_CFLAGS_COMPILE"
echo "ac_add_options BINDGEN_CFLAGS='$BINDGEN_CFLAGS'" >> $MOZCONFIG echo "ac_add_options BINDGEN_CFLAGS='$BINDGEN_CFLAGS'" >> $MOZCONFIG
'' + lib.optionalString googleAPISupport '' '' + (lib.optionalString googleAPISupport ''
# Google API key used by Chromium and Firefox. # Google API key used by Chromium and Firefox.
# Note: These are for NixOS/nixpkgs use ONLY. For your own distribution, # Note: These are for NixOS/nixpkgs use ONLY. For your own distribution,
# please get your own set of keys. # please get your own set of keys.
echo "AIzaSyDGi15Zwl11UNe6Y-5XW_upsfyw31qwZPI" > $TMPDIR/ga echo "AIzaSyDGi15Zwl11UNe6Y-5XW_upsfyw31qwZPI" > $TMPDIR/ga
# 60.5+ & 66+ did split the google API key arguments: https://bugzilla.mozilla.org/show_bug.cgi?id=1531176 # 60.5+ & 66+ did split the google API key arguments: https://bugzilla.mozilla.org/show_bug.cgi?id=1531176
${if (lib.versionAtLeast ffversion "60.6" && lib.versionOlder ffversion "61") || (lib.versionAtLeast ffversion "66") then ''
configureFlagsArray+=("--with-google-location-service-api-keyfile=$TMPDIR/ga") configureFlagsArray+=("--with-google-location-service-api-keyfile=$TMPDIR/ga")
configureFlagsArray+=("--with-google-safebrowsing-api-keyfile=$TMPDIR/ga") configureFlagsArray+=("--with-google-safebrowsing-api-keyfile=$TMPDIR/ga")
'' else '' '') + ''
configureFlagsArray+=("--with-google-api-keyfile=$TMPDIR/ga")
''}
'' + lib.optionalString (lib.versionOlder ffversion "58") ''
cd obj-*
''
# AS=as in the environment causes build failure https://bugzilla.mozilla.org/show_bug.cgi?id=1497286 # AS=as in the environment causes build failure https://bugzilla.mozilla.org/show_bug.cgi?id=1497286
+ lib.optionalString (lib.versionAtLeast ffversion "64") ''
unset AS unset AS
''; '';
@ -255,32 +229,15 @@ stdenv.mkDerivation (rec {
"--enable-jemalloc" "--enable-jemalloc"
"--disable-gconf" "--disable-gconf"
"--enable-default-toolkit=${default-toolkit}" "--enable-default-toolkit=${default-toolkit}"
]
++ lib.optional (lib.versionOlder ffversion "64") "--disable-maintenance-service"
++ lib.optional (stdenv.isDarwin && lib.versionAtLeast ffversion "61") "--disable-xcode-checks"
++ lib.optional (lib.versionOlder ffversion "61") "--enable-system-hunspell"
++ lib.optionals (lib.versionAtLeast ffversion "56") [
"--with-libclang-path=${llvmPackages.libclang}/lib" "--with-libclang-path=${llvmPackages.libclang}/lib"
"--with-clang-path=${llvmPackages.clang}/bin/clang" "--with-clang-path=${llvmPackages.clang}/bin/clang"
]
++ lib.optionals (lib.versionAtLeast ffversion "57" && lib.versionOlder ffversion "69") [
"--enable-webrender=build"
]
# TorBrowser patches these
++ lib.optionals (!isTorBrowserLike) [
"--with-system-nspr" "--with-system-nspr"
"--with-system-nss" "--with-system-nss"
] ]
++ lib.optional (stdenv.isDarwin) "--disable-xcode-checks"
# and wants these ++ lib.optionals (lib.versionOlder ffversion "69") [
++ lib.optionals isTorBrowserLike ([ "--enable-webrender=build"
"--with-tor-browser-version=${tbversion}" ]
"--with-distribution-id=org.torproject"
"--enable-signmar"
"--enable-verify-mar"
"--enable-bundled-fonts"
])
++ flag alsaSupport "alsa" ++ flag alsaSupport "alsa"
++ flag pulseaudioSupport "pulseaudio" ++ flag pulseaudioSupport "pulseaudio"
@ -290,11 +247,6 @@ stdenv.mkDerivation (rec {
++ flag crashreporterSupport "crashreporter" ++ flag crashreporterSupport "crashreporter"
++ lib.optional drmSupport "--enable-eme=widevine" ++ lib.optional drmSupport "--enable-eme=widevine"
++ lib.optionals (lib.versionOlder ffversion "60") ([]
++ flag geolocationSupport "mozril-geoloc"
++ flag safeBrowsingSupport "safe-browsing"
)
++ (if debugBuild then [ "--enable-debug" "--enable-profiling" ] ++ (if debugBuild then [ "--enable-debug" "--enable-profiling" ]
else [ "--disable-debug" "--enable-release" else [ "--disable-debug" "--enable-release"
"--enable-optimize" "--enable-optimize"
@ -302,29 +254,16 @@ stdenv.mkDerivation (rec {
++ lib.optional enableOfficialBranding "--enable-official-branding" ++ lib.optional enableOfficialBranding "--enable-official-branding"
++ extraConfigureFlags; ++ extraConfigureFlags;
# Before 58 we have to run `make -f client.mk configure-files` at postConfigure = ''
# the top level, and then run `./configure` in the obj-* dir (see
# above), but in 58 we have to instead run `./mach configure` at the
# top level and then run `make` in obj-*. (We can also run the
# `make` at the top level in 58, but then we would have to `cd` to
# `make install` anyway. This is ugly, but simple.)
postConfigure = lib.optionalString (lib.versionAtLeast ffversion "58") ''
cd obj-* cd obj-*
''; '';
preBuild = lib.optionalString isTorBrowserLike ''
buildFlagsArray=("MOZ_APP_DISPLAYNAME=Tor Browser")
'';
makeFlags = lib.optionals enableOfficialBranding [ makeFlags = lib.optionals enableOfficialBranding [
"MOZILLA_OFFICIAL=1" "MOZILLA_OFFICIAL=1"
"BUILD_OFFICIAL=1" "BUILD_OFFICIAL=1"
] ]
++ extraMakeFlags; ++ extraMakeFlags;
RUSTFLAGS = if (lib.versionAtLeast ffversion "67"/*somewhere betwween ESRs*/)
then null else "--cap-lints warn";
enableParallelBuilding = true; enableParallelBuilding = true;
doCheck = false; # "--disable-tests" above doCheck = false; # "--disable-tests" above
@ -355,10 +294,9 @@ stdenv.mkDerivation (rec {
''; '';
passthru = { passthru = {
inherit version updateScript; inherit updateScript;
version = ffversion;
isFirefox3Like = true; isFirefox3Like = true;
inherit isIceCatLike;
inherit isTorBrowserLike;
gtk = gtk2; gtk = gtk2;
inherit nspr; inherit nspr;
inherit ffmpegSupport; inherit ffmpegSupport;
@ -366,12 +304,12 @@ stdenv.mkDerivation (rec {
inherit execdir; inherit execdir;
inherit browserName; inherit browserName;
} // lib.optionalAttrs gtk3Support { inherit gtk3; }; } // lib.optionalAttrs gtk3Support { inherit gtk3; };
} // } //
# the build system verifies checksums of the bundled rust sources # the build system verifies checksums of the bundled rust sources
# ./third_party/rust is be patched by our libtool fixup code in stdenv # ./third_party/rust is be patched by our libtool fixup code in stdenv
# unfortunately we can't just set this to `false` when we do not want it. # unfortunately we can't just set this to `false` when we do not want it.
# See https://github.com/NixOS/nixpkgs/issues/77289 for more details # See https://github.com/NixOS/nixpkgs/issues/77289 for more details
lib.optionalAttrs (lib.versionAtLeast ffversion "72") { lib.optionalAttrs (lib.versionAtLeast ffversion "72") {
# Ideally we would figure out how to tell the build system to not # Ideally we would figure out how to tell the build system to not
# care about changed hashes as we are already doing that when we # care about changed hashes as we are already doing that when we