2022-03-21 20:09:59 +01:00
{
pname ,
version ,
2023-10-10 17:35:11 +02:00
packageVersion ? version ,
2022-03-21 20:09:59 +01:00
meta ,
updateScript ? null ,
binaryName ? " f i r e f o x " ,
application ? " b r o w s e r " ,
2025-01-29 20:35:46 -05:00
applicationName ? " F i r e f o x " ,
2023-03-23 17:47:51 +01:00
branding ? null ,
2023-07-20 19:13:51 -04:00
requireSigning ? true ,
2023-11-14 09:40:05 -05:00
allowAddonSideload ? false ,
2022-03-21 20:09:59 +01:00
src ,
unpackPhase ? null ,
2022-03-21 03:44:02 +01:00
extraPatches ? [ ] ,
extraPostPatch ? " " ,
extraNativeBuildInputs ? [ ] ,
extraConfigureFlags ? [ ] ,
2022-03-21 20:09:59 +01:00
extraBuildInputs ? [ ] ,
2022-03-21 03:44:02 +01:00
extraMakeFlags ? [ ] ,
extraPassthru ? { } ,
2024-10-19 14:12:19 +02:00
tests ? { } ,
2022-03-21 03:44:02 +01:00
} :
2023-11-25 02:30:25 -05:00
let
# Rename the variables to prevent infinite recursion
requireSigningDefault = requireSigning ;
allowAddonSideloadDefault = allowAddonSideload ;
2024-12-14 20:10:17 +01:00
# Specifying --(dis|en)able-elf-hack on a platform for which it's not implemented will give `--disable-elf-hack is not available in this configuration`
# This is declared here because it's used in the default value of elfhackSupport
2024-12-14 20:22:09 +01:00
isElfhackPlatform =
stdenv :
stdenv . hostPlatform . isElf
&& (
stdenv . hostPlatform . isi686
|| stdenv . hostPlatform . isx86_64
|| stdenv . hostPlatform . isAarch32
|| stdenv . hostPlatform . isAarch64
) ;
2023-11-25 02:30:25 -05:00
in
2017-03-27 12:33:00 +00:00
2022-03-21 20:09:59 +01:00
{
lib ,
2022-05-16 00:26:57 +02:00
pkgs ,
2022-03-21 20:09:59 +01:00
stdenv ,
2022-11-08 00:02:25 +01:00
patchelf ,
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# build time
autoconf ,
cargo ,
2022-05-12 14:40:21 +02:00
dump_syms ,
2022-03-21 20:09:59 +01:00
makeWrapper ,
2022-08-15 11:50:26 +02:00
mimalloc ,
2022-03-21 20:09:59 +01:00
nodejs ,
perl ,
pkg-config ,
pkgsCross , # wasm32 rlbox
python3 ,
runCommand ,
rustc ,
rust-cbindgen ,
rustPlatform ,
unzip ,
which ,
2024-04-26 22:24:03 +02:00
wrapGAppsHook3 ,
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# runtime
bzip2 ,
dbus ,
dbus-glib ,
file ,
fontconfig ,
freetype ,
glib ,
gnum4 ,
gtk3 ,
2024-06-27 14:50:47 +02:00
icu73 ,
2025-05-16 08:06:52 +02:00
icu77 , # if you fiddle with the icu parameters, please check Thunderbird's overrides
2022-03-21 20:09:59 +01:00
libGL ,
libGLU ,
libevent ,
2022-03-21 18:16:55 +01:00
libffi ,
2022-03-21 20:09:59 +01:00
libjpeg ,
libpng ,
libstartup_notification ,
2021-11-29 17:09:07 +08:00
libvpx ,
2022-03-21 03:45:46 +01:00
libwebp ,
2022-03-21 20:09:59 +01:00
nasm ,
nspr ,
2022-03-30 01:18:38 +02:00
nss_esr ,
nss_latest ,
2022-03-21 20:09:59 +01:00
pango ,
xorg ,
zip ,
zlib ,
2022-05-03 10:23:35 +08:00
pkgsBuildBuild ,
2025-04-01 20:10:43 +02:00
2024-10-20 22:55:34 -04:00
# Darwin
apple-sdk_14 ,
2025-04-19 15:08:02 -05:00
apple-sdk_15 ,
2024-10-20 22:55:34 -04:00
cups ,
rsync , # used when preparing .app directory
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# optionals
2025-04-01 20:10:43 +02:00
2023-11-25 02:30:25 -05:00
## addon signing/sideloading
requireSigning ? requireSigningDefault ,
allowAddonSideload ? allowAddonSideloadDefault ,
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
## debugging
2025-04-01 20:10:43 +02:00
2013-10-05 21:07:42 -07:00
debugBuild ? false ,
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# On 32bit platforms, we disable adding "-g" for easier linking.
enableDebugSymbols ? ! stdenv . hostPlatform . is32bit ,
2025-04-01 20:10:43 +02:00
2017-03-27 12:35:34 +00:00
## optional libraries
2025-04-01 20:10:43 +02:00
2021-06-09 23:57:09 -03:00
alsaSupport ? stdenv . hostPlatform . isLinux ,
alsa-lib ,
2018-11-14 22:29:48 +00:00
ffmpegSupport ? true ,
2021-03-14 17:11:48 +01:00
gssSupport ? true ,
libkrb5 ,
2022-05-07 18:31:10 -04:00
jackSupport ? stdenv . hostPlatform . isLinux ,
libjack2 ,
2022-08-15 11:50:26 +02:00
jemallocSupport ? ! stdenv . hostPlatform . isMusl ,
jemalloc ,
2023-03-30 23:03:07 +08:00
ltoSupport ? (
stdenv . hostPlatform . isLinux && stdenv . hostPlatform . is64bit && ! stdenv . hostPlatform . isRiscV
) ,
overrideCC ,
buildPackages ,
2022-10-18 20:18:18 +02:00
pgoSupport ? ( stdenv . hostPlatform . isLinux && stdenv . hostPlatform = = stdenv . buildPlatform ) ,
xvfb-run ,
2024-12-14 20:10:17 +01:00
elfhackSupport ?
isElfhackPlatform stdenv && ! ( stdenv . hostPlatform . isMusl && stdenv . hostPlatform . isAarch64 ) ,
2022-03-21 20:09:59 +01:00
pipewireSupport ? waylandSupport && webrtcSupport ,
pulseaudioSupport ? stdenv . hostPlatform . isLinux ,
libpulseaudio ,
2022-05-07 18:31:10 -04:00
sndioSupport ? stdenv . hostPlatform . isLinux ,
sndio ,
2025-01-29 20:35:46 -05:00
waylandSupport ? ! stdenv . hostPlatform . isDarwin ,
libxkbcommon ,
libdrm ,
2025-04-01 20:10:43 +02:00
2017-03-27 12:35:34 +00:00
## privacy-related options
2025-04-01 20:10:43 +02:00
2020-02-01 18:56:13 +01:00
privacySupport ? false ,
2025-04-01 20:10:43 +02:00
2017-03-27 12:35:34 +00:00
# WARNING: NEVER set any of the options below to `true` by default.
2019-04-06 23:49:14 +09:00
# Set to `!privacySupport` or `false`.
2025-04-01 20:10:43 +02:00
2022-08-15 11:50:26 +02:00
crashreporterSupport ?
2025-05-02 02:10:11 +02:00
! privacySupport
&& ! stdenv . hostPlatform . isLoongArch64
&& ! stdenv . hostPlatform . isRiscV
&& ! stdenv . hostPlatform . isMusl ,
2022-08-15 11:50:26 +02:00
curl ,
2017-11-15 00:00:00 +00:00
geolocationSupport ? ! privacySupport ,
2024-03-25 16:49:20 -04:00
webrtcSupport ? ! privacySupport ,
2025-04-01 20:10:43 +02:00
2022-03-28 15:26:04 +02:00
# digital rights managemewnt
2025-04-01 20:10:43 +02:00
2022-03-28 15:26:04 +02:00
# This flag controls whether Firefox will show the nagbar, that allows
# users at runtime the choice to enable Widevine CDM support when a site
# requests it.
# Controlling the nagbar and widevine CDM at runtime is possible by setting
# `browser.eme.ui.enabled` and `media.gmp-widevinecdm.enabled` accordingly
drmSupport ? true ,
2025-04-01 20:10:43 +02:00
2018-01-31 17:50:10 +01:00
# As stated by Sylvestre Ledru (@sylvestre) on Nov 22, 2017 at
# https://github.com/NixOS/nixpkgs/issues/31843#issuecomment-346372756 we
# have permission to use the official firefox branding.
#
2020-07-24 09:49:43 +02:00
# For purposes of documentation the statement of @sylvestre:
2018-01-31 17:50:10 +01:00
# > As the person who did part of the work described in the LWN article
# > and release manager working for Mozilla, I can confirm the statement
# > that I made in
# > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815006
# >
# > @garbas shared with me the list of patches applied for the Nix package.
# > As they are just for portability and tiny modifications, they don't
# > alter the experience of the product. In parallel, Rok also shared the
# > build options. They seem good (even if I cannot judge the quality of the
# > packaging of the underlying dependencies like sqlite, png, etc).
# > Therefor, as long as you keep the patch queue sane and you don't alter
# > the experience of Firefox users, you won't have any issues using the
# > official branding.
enableOfficialBranding ? true ,
2013-06-06 13:07:54 +02:00
} :
2018-02-01 00:00:00 +00:00
assert stdenv . cc . libc or null != null ;
2022-03-27 15:10:43 +02:00
assert
pipewireSupport
-> ! waylandSupport || ! webrtcSupport
-> throw " ${ pname } : p i p e w i r e S u p p o r t r e q u i r e s b o t h w a y l a n d a n d w e b r t c s u p p o r t . " ;
2024-12-14 20:10:17 +01:00
assert elfhackSupport -> isElfhackPlatform stdenv ;
2013-06-06 13:07:54 +02:00
2015-09-03 10:54:13 +02:00
let
2022-11-24 15:56:43 -03:00
inherit ( lib ) enableFeature ;
2018-07-10 18:10:04 -04:00
2022-03-21 20:09:59 +01:00
# Target the LLVM version that rustc is built with for LTO.
2022-03-21 16:03:59 +01:00
llvmPackages0 = rustc . llvmPackages ;
2022-05-03 10:23:35 +08:00
llvmPackagesBuildBuild0 = pkgsBuildBuild . rustc . llvmPackages ;
2021-11-02 10:39:56 +01:00
2021-05-01 03:03:19 +00:00
# Force the use of lld and other llvm tools for LTO
llvmPackages = llvmPackages0 . override {
bootBintoolsNoLibc = null ;
bootBintools = null ;
} ;
2022-05-03 10:23:35 +08:00
llvmPackagesBuildBuild = llvmPackagesBuildBuild0 . override {
bootBintoolsNoLibc = null ;
bootBintools = null ;
} ;
2020-10-06 14:14:06 -04:00
2022-03-27 17:12:20 +02:00
# LTO requires LLVM bintools including ld.lld and llvm-ar.
buildStdenv = overrideCC llvmPackages . stdenv (
llvmPackages . stdenv . cc . override {
2022-05-03 10:23:35 +08:00
bintools = if ltoSupport then buildPackages . rustc . llvmPackages . bintools else stdenv . cc . bintools ;
2022-03-27 17:12:20 +02:00
}
) ;
2020-11-07 14:53:42 +01:00
2022-03-09 19:40:08 +01:00
# Compile the wasm32 sysroot to build the RLBox Sandbox
# https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/
# We only link c++ libs here, our compiler wrapper can find wasi libc and crt itself.
wasiSysRoot = runCommand " w a s i - s y s r o o t " { } ''
mkdir - p $ out/lib/wasm32-wasi
llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx (#292043)
- merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git.
- remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required.
- fixes https://github.com/NixOS/nixpkgs/issues/166205
- provides alternative fixes for. https://github.com/NixOS/nixpkgs/issues/269548 https://github.com/NixOS/nix/issues/9640
- pkgsCross.x86_64-freebsd builds work again
This change can be represented in 3 stages
1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi}
2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin}
3. remove all references to libcxxabi outside of llvm (about 58 packages modified)
### merging libcxxabi into libcxx
- take the union of the libcxxabi and libcxx cmake flags
- eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency
- libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx.
- darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient.
- linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient.
- libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+)
- git/libcxx/defaul.nix does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway.
### stdenv changes
- darwin bootstrap, remove references to libcxxabi and cxxabi
- cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12)
- adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx
### 58 package updates
- remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed
- swift, nodejs_v8 remove libcxxabi references in the clang override
https://github.com/NixOS/nixpkgs/pull/292043
2024-03-11 03:53:37 -07:00
for lib in $ { pkgsCross . wasi32 . llvmPackages . libcxx } /lib /* ; d o
2022-03-09 19:40:08 +01:00
ln - s $ lib $ out/lib/wasm32-wasi
done
'' ;
2022-05-16 00:26:57 +02:00
2025-01-29 20:35:46 -05:00
distributionIni =
let
platform = if stdenv . hostPlatform . isDarwin then " N i x o n M a c O S " else " N i x O S " ;
in
pkgs . writeText " d i s t r i b u t i o n . i n i " (
lib . generators . toINI { } {
2022-05-16 00:26:57 +02:00
# Some light branding indicating this build uses our distro preferences
Global = {
id = " n i x o s " ;
version = " 1 . 0 " ;
2025-01-29 20:35:46 -05:00
about = " ${ applicationName } f o r ${ platform } " ;
2022-05-16 00:26:57 +02:00
} ;
Preferences = {
# These values are exposed through telemetry
" a p p . d i s t r i b u t o r " = " n i x o s " ;
" a p p . d i s t r i b u t o r . c h a n n e l " = " n i x p k g s " ;
} ;
}
) ;
2025-04-30 23:51:42 +02:00
defaultPrefs =
if geolocationSupport then
{
" g e o . p r o v i d e r . n e t w o r k . u r l " = {
value = " h t t p s : / / a p i . b e a c o n d b . n e t / v 1 / g e o l o c a t e " ;
reason = " W e h a v e n o G o o g l e A P I k e y s a n d M o z i l l a L o c a t i o n S e r v i c e s w e r e r e t i r e d . " ;
} ;
}
else
{
" g e o . p r o v i d e r . u s e _ g e o c l u e " = {
value = false ;
reason = " G e o l o c a t i o n s u p p o r t h a s b e e n d i s a b l e d t h r o u g h t h e ` g e o l o c a t i o n S u p p o r t ` p a c k a g e a t t r i b u t e . " ;
} ;
} ;
2022-05-22 01:49:20 +02:00
defaultPrefsFile = pkgs . writeText " n i x o s - d e f a u l t - p r e f s . j s " (
lib . concatStringsSep " \n " (
lib . mapAttrsToList ( key : value : ''
// $ { value . reason }
pref ( " ${ key } " , $ { builtins . toJSON value . value } ) ;
'' ) d e f a u l t P r e f s
2025-04-01 20:10:43 +02:00
)
2022-05-22 01:49:20 +02:00
) ;
2024-10-20 22:55:34 -04:00
toolkit =
if stdenv . hostPlatform . isDarwin then
" c a i r o - c o c o a "
else
" c a i r o - g t k 3 ${ lib . optionalString waylandSupport " - w a y l a n d " } " ;
2020-02-01 18:56:13 +01:00
in
2023-06-22 19:04:37 -04:00
buildStdenv . mkDerivation {
2022-08-02 14:22:42 +02:00
pname = " ${ pname } - u n w r a p p e d " ;
2023-10-10 17:35:11 +02:00
version = packageVersion ;
2019-01-01 00:00:00 +00:00
2020-02-01 18:56:13 +01:00
inherit src unpackPhase meta ;
2019-01-31 16:38:01 +00:00
2022-05-12 14:40:21 +02:00
outputs = [
" o u t "
2022-05-16 13:52:15 -07:00
] ++ lib . optionals crashreporterSupport [ " s y m b o l s " ] ;
2022-05-12 14:40:21 +02:00
2022-03-22 03:35:51 +01:00
# Add another configure-build-profiling run before the final configure phase if we build with pgo
preConfigurePhases = lib . optionals pgoSupport [
" c o n f i g u r e P h a s e "
" b u i l d P h a s e "
" p r o f i l i n g P h a s e "
] ;
2024-10-29 21:28:50 +01:00
patches =
lib . optionals ( lib . versionAtLeast version " 1 1 1 " && lib . versionOlder version " 1 3 3 " ) [
./env_var_for_system_dir-ff111.patch
]
++ lib . optionals ( lib . versionAtLeast version " 1 3 3 " ) [ ./env_var_for_system_dir-ff133.patch ]
2025-03-03 23:17:00 +01:00
++ lib . optionals ( lib . versionAtLeast version " 1 2 1 " && lib . versionOlder version " 1 3 6 " ) [
./no-buildconfig-ffx121.patch
2025-04-01 20:10:43 +02:00
]
2025-03-03 23:17:00 +01:00
++ lib . optionals ( lib . versionAtLeast version " 1 3 6 " ) [ ./no-buildconfig-ffx136.patch ]
2025-05-26 22:05:27 +02:00
++ lib . optionals ( lib . versionAtLeast version " 1 3 9 " ) [ ./139-relax-apple-sdk.patch ]
++ lib . optionals ( lib . versionOlder version " 1 3 9 " ) [
2024-12-29 17:57:37 -05:00
# Fix for missing vector header on macOS
2025-05-10 20:19:10 -04:00
# https://bugzilla.mozilla.org/show_bug.cgi?id=1959377
# Fixed on Firefox 139
2024-12-29 17:57:37 -05:00
./firefox-mac-missing-vector-header.patch
2025-05-26 22:05:27 +02:00
]
++ lib . optionals ( lib . versionOlder version " 1 4 0 " ) [
2025-04-23 21:47:11 -07:00
# https://bugzilla.mozilla.org/show_bug.cgi?id=1962497
# https://phabricator.services.mozilla.com/D246545
2025-05-10 20:19:10 -04:00
# Fixed on Firefox 140
2025-04-23 21:47:11 -07:00
./build-fix-RELRHACK_LINKER-setting-when-linker-name-i.patch
2024-11-07 01:20:18 +00:00
]
2022-03-21 03:44:02 +01:00
++ extraPatches ;
2025-04-01 20:10:43 +02:00
2022-03-21 03:44:02 +01:00
postPatch =
''
rm - rf obj-x86_64-pc-linux-gnu
2022-12-12 17:10:29 +01:00
patchShebangs mach build
2022-03-21 20:09:59 +01:00
''
2025-05-12 03:49:34 +02:00
# https://bugzilla.mozilla.org/show_bug.cgi?id=1927380
+ lib . optionalString ( lib . versionAtLeast version " 1 3 4 " ) ''
sed - i " s / i c u - i 1 8 n / i c u - u c & / " js/moz.configure
''
2022-03-21 20:09:59 +01:00
+ extraPostPatch ;
2017-03-27 12:33:00 +00:00
2019-01-23 01:04:04 +01:00
# Ignore trivial whitespace changes in patches, this fixes compatibility of
2024-10-20 22:55:34 -04:00
# ./env_var_for_system_dir-*.patch with Firefox >=65 without having to track
2019-01-23 01:04:04 +01:00
# two patches.
patchFlags = [
" - p 1 "
" - l "
] ;
2022-05-03 10:23:35 +08:00
# if not explicitly set, wrong cc from buildStdenv would be used
HOST_CC = " ${ llvmPackagesBuildBuild . stdenv . cc } / b i n / c c " ;
HOST_CXX = " ${ llvmPackagesBuildBuild . stdenv . cc } / b i n / c + + " ;
2022-03-21 20:09:59 +01:00
nativeBuildInputs =
[
autoconf
cargo
2022-05-03 10:23:35 +08:00
gnum4
llvmPackagesBuildBuild . bintools
2022-03-21 20:09:59 +01:00
makeWrapper
nodejs
perl
python3
rust-cbindgen
rustPlatform . bindgenHook
rustc
unzip
which
2024-04-26 22:24:03 +02:00
wrapGAppsHook3
2017-03-27 12:33:00 +00:00
]
2024-10-20 22:55:34 -04:00
++ lib . optionals ( ! stdenv . hostPlatform . isDarwin ) [ pkg-config ]
++ lib . optionals stdenv . hostPlatform . isDarwin [ rsync ]
2025-04-23 17:03:26 -07:00
++ lib . optionals stdenv . hostPlatform . isx86 [ nasm ]
2022-11-08 00:02:25 +01:00
++ lib . optionals crashreporterSupport [
dump_syms
patchelf
]
2022-03-22 03:35:51 +01:00
++ lib . optionals pgoSupport [ xvfb-run ]
2022-03-21 20:09:59 +01:00
++ extraNativeBuildInputs ;
2017-03-27 12:33:00 +00:00
2021-11-16 18:38:56 +08:00
setOutputFlags = false ; # `./mach configure` doesn't understand `--*dir=` flags.
2017-03-27 12:33:00 +00:00
preConfigure =
''
2022-03-21 20:09:59 +01:00
# Runs autoconf through ./mach configure in configurePhase
2018-02-01 00:00:00 +00:00
configureScript = " $ ( r e a l p a t h . / m a c h ) c o n f i g u r e "
2025-04-01 20:10:43 +02:00
2024-01-30 23:52:12 +01:00
# Set reproducible build date; https://bugzilla.mozilla.org/show_bug.cgi?id=885777#c21
export MOZ_BUILD_DATE = $ ( head - n1 sourcestamp . txt )
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# Set predictable directories for build and state
2024-04-28 16:13:25 +02:00
export MOZ_OBJDIR = $ ( pwd ) /objdir
export MOZBUILD_STATE_PATH = $ TMPDIR/mozbuild
2025-04-01 20:10:43 +02:00
2022-03-22 03:35:51 +01:00
# Don't try to send libnotify notifications during build
export MOZ_NOSPAM = 1
2025-04-01 20:10:43 +02:00
2022-03-21 15:20:36 +01:00
# Set consistent remoting name to ensure wmclass matches with desktop file
export MOZ_APP_REMOTINGNAME = " ${ binaryName } "
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
# AS=as in the environment causes build failure
# https://bugzilla.mozilla.org/show_bug.cgi?id=1497286
unset AS
2025-04-01 20:10:43 +02:00
2022-05-12 15:16:44 +02:00
# Use our own python
export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE = system
2025-04-01 20:10:43 +02:00
2022-03-09 19:40:08 +01:00
# RBox WASM Sandboxing
export WASM_CC = $ { pkgsCross . wasi32 . stdenv . cc } /bin / $ { pkgsCross . wasi32 . stdenv . cc . targetPrefix } cc
export WASM_CXX = $ { pkgsCross . wasi32 . stdenv . cc } /bin / $ { pkgsCross . wasi32 . stdenv . cc . targetPrefix } c ++
2023-04-26 15:18:38 +02:00
''
+ lib . optionalString pgoSupport ''
if [ - e " $ T M P D I R / m e r g e d . p r o f d a t a " ] ; then
echo " C o n f i g u r i n g w i t h p r o f i l i n g d a t a "
for i in " ' ' ${ ! configureFlagsArray [ @ ] } " ; do
if [ [ '' ${ configureFlagsArray [ i ] } = " - - e n a b l e - p r o f i l e - g e n e r a t e = c r o s s " ] ] ; t h e n
unset ' configureFlagsArray [ i ] '
fi
done
2024-01-28 03:01:45 +01:00
appendToVar configureFlags - - enable-profile-use = cross
appendToVar configureFlags - - with-pgo-profile-path = $ TMPDIR/merged.profdata
appendToVar configureFlags - - with-pgo-jarlog = $ TMPDIR/jarlog
2023-04-26 15:18:38 +02:00
$ { lib . optionalString stdenv . hostPlatform . isMusl ''
LDFLAGS = " $ O L D _ L D F L A G S "
unset OLD_LDFLAGS
'' }
else
echo " C o n f i g u r i n g t o g e n e r a t e p r o f i l i n g d a t a "
configureFlagsArray + = (
" - - e n a b l e - p r o f i l e - g e n e r a t e = c r o s s "
)
$ { lib . optionalString stdenv . hostPlatform . isMusl
# Set the rpath appropriately for the profiling run
# During the profiling run, loading libraries from $out would fail,
# since the profiling build has not been installed to $out
''
OLD_LDFLAGS = " $ L D F L A G S "
2024-04-28 16:13:25 +02:00
LDFLAGS = " - W l , - r p a t h , $ ( p w d ) / o b j d i r / d i s t / ${ binaryName } "
2023-04-26 15:18:38 +02:00
''
}
fi
2022-03-21 20:09:59 +01:00
''
2022-05-29 07:28:42 +01:00
+ lib . optionalString ( enableOfficialBranding && ! stdenv . hostPlatform . is32bit ) ''
2021-08-11 20:14:23 -04:00
export MOZILLA_OFFICIAL = 1
2023-07-20 19:13:51 -04:00
''
+ lib . optionalString ( ! requireSigning ) ''
export MOZ_REQUIRE_SIGNING =
2022-08-15 11:50:26 +02:00
''
+ lib . optionalString stdenv . hostPlatform . isMusl ''
# linking firefox hits the vm.max_map_count kernel limit with the default musl allocator
2023-06-21 19:23:08 +02:00
# TODO: Default vm.max_map_count has been increased, retest without this
2022-08-15 11:50:26 +02:00
export LD_PRELOAD = $ { mimalloc } /lib/libmimalloc.so
2022-03-21 20:09:59 +01:00
'' ;
2017-03-27 12:33:00 +00:00
2022-05-03 10:23:35 +08:00
# firefox has a different definition of configurePlatforms from nixpkgs, see configureFlags
configurePlatforms = [ ] ;
2017-03-27 12:33:00 +00:00
configureFlags =
[
2022-03-21 20:09:59 +01:00
" - - d i s a b l e - t e s t s "
" - - d i s a b l e - u p d a t e r "
2021-07-13 19:04:57 +02:00
" - - e n a b l e - a p p l i c a t i o n = ${ application } "
2024-10-20 22:55:34 -04:00
" - - e n a b l e - d e f a u l t - t o o l k i t = ${ toolkit } "
2025-01-05 21:27:45 -05:00
" - - w i t h - a p p - n a m e = ${ binaryName } "
2022-05-16 00:26:57 +02:00
" - - w i t h - d i s t r i b u t i o n - i d = o r g . n i x o s "
2024-11-07 09:43:39 +00:00
" - - w i t h - l i b c l a n g - p a t h = ${ lib . getLib llvmPackagesBuildBuild . libclang } / l i b "
2022-12-03 22:39:23 +01:00
" - - w i t h - w a s i - s y s r o o t = ${ wasiSysRoot } "
2022-05-03 10:23:35 +08:00
# for firefox, host is buildPlatform, target is hostPlatform
" - - h o s t = ${ buildStdenv . buildPlatform . config } "
" - - t a r g e t = ${ buildStdenv . hostPlatform . config } "
2017-04-01 00:00:00 +00:00
]
2020-10-08 21:55:23 -04:00
# LTO is done using clang and lld on Linux.
2022-03-21 20:09:59 +01:00
++ lib . optionals ltoSupport [
2024-12-20 19:32:30 +01:00
" - - e n a b l e - l t o = c r o s s , f u l l " # Cross-Language LTO
2022-03-21 20:09:59 +01:00
" - - e n a b l e - l i n k e r = l l d "
]
2024-12-14 20:10:17 +01:00
++ lib . optional ( isElfhackPlatform stdenv ) ( enableFeature elfhackSupport " e l f - h a c k " )
2022-03-28 15:26:04 +02:00
++ lib . optional ( ! drmSupport ) " - - d i s a b l e - e m e "
2025-05-12 03:49:16 +02:00
++ lib . optional allowAddonSideload " - - a l l o w - a d d o n - s i d e l o a d "
2024-10-20 22:55:34 -04:00
++ lib . optionals ( ! stdenv . hostPlatform . isDarwin ) [
# MacOS builds use bundled versions of libraries: https://bugzilla.mozilla.org/show_bug.cgi?id=1776255
" - - e n a b l e - s y s t e m - p i x m a n "
" - - w i t h - s y s t e m - f f i "
2025-05-12 03:49:34 +02:00
" - - w i t h - s y s t e m - i c u "
2024-10-20 22:55:34 -04:00
" - - w i t h - s y s t e m - j p e g "
" - - w i t h - s y s t e m - l i b e v e n t "
" - - w i t h - s y s t e m - l i b v p x "
" - - w i t h - s y s t e m - n s p r "
" - - w i t h - s y s t e m - n s s "
" - - w i t h - s y s t e m - p n g " # needs APNG support
" - - w i t h - s y s t e m - w e b p "
" - - w i t h - s y s t e m - z l i b "
2025-04-01 20:10:43 +02:00
2024-10-20 22:55:34 -04:00
# These options are not available on MacOS, even --disable-*
2022-11-24 15:56:43 -03:00
( enableFeature alsaSupport " a l s a " )
2024-10-20 22:55:34 -04:00
( enableFeature jackSupport " j a c k " )
( enableFeature pulseaudioSupport " p u l s e a u d i o " )
( enableFeature sndioSupport " s n d i o " )
]
++ [
2022-11-24 15:56:43 -03:00
( enableFeature crashreporterSupport " c r a s h r e p o r t e r " )
( enableFeature ffmpegSupport " f f m p e g " )
( enableFeature geolocationSupport " n e c k o - w i f i " )
( enableFeature gssSupport " n e g o t i a t e a u t h " )
( enableFeature jemallocSupport " j e m a l l o c " )
( enableFeature webrtcSupport " w e b r t c " )
2025-04-01 20:10:43 +02:00
2022-11-24 15:56:43 -03:00
( enableFeature debugBuild " d e b u g " )
( if debugBuild then " - - e n a b l e - p r o f i l i n g " else " - - e n a b l e - o p t i m i z e " )
# --enable-release adds -ffunction-sections & LTO that require a big amount
# of RAM, and the 32-bit memory space cannot handle that linking
( enableFeature ( ! debugBuild && ! stdenv . hostPlatform . is32bit ) " r e l e a s e " )
( enableFeature enableDebugSymbols " d e b u g - s y m b o l s " )
]
2021-11-16 18:38:56 +08:00
++ lib . optionals enableDebugSymbols [
" - - d i s a b l e - s t r i p "
" - - d i s a b l e - i n s t a l l - s t r i p "
]
2025-03-13 22:16:28 -04:00
# As of Firefox 137 (https://bugzilla.mozilla.org/show_bug.cgi?id=1943009),
# the --enable-official-branding flag overrides the --with-branding flag.
++ lib . optional ( enableOfficialBranding && branding = = null ) " - - e n a b l e - o f f i c i a l - b r a n d i n g "
2023-03-23 17:47:51 +01:00
++ lib . optional ( branding != null ) " - - w i t h - b r a n d i n g = ${ branding } "
2017-08-15 00:00:00 +00:00
++ extraConfigureFlags ;
2025-04-01 20:10:43 +02:00
2022-03-21 20:09:59 +01:00
buildInputs =
[
bzip2
2024-10-20 22:55:34 -04:00
file
libGL
libGLU
libstartup_notification
perl
zip
]
++ lib . optionals stdenv . hostPlatform . isDarwin [
2025-04-19 15:08:02 -05:00
( if lib . versionAtLeast version " 1 3 8 " then apple-sdk_15 else apple-sdk_14 )
2024-10-20 22:55:34 -04:00
cups
]
++ ( lib . optionals ( ! stdenv . hostPlatform . isDarwin ) (
[
2022-03-21 20:09:59 +01:00
dbus
dbus-glib
fontconfig
freetype
glib
gtk3
libffi
libevent
libjpeg
libpng
libvpx
libwebp
nspr
pango
xorg . libX11
xorg . libXcursor
xorg . libXdamage
xorg . libXext
xorg . libXft
xorg . libXi
xorg . libXrender
xorg . libXt
xorg . libXtst
xorg . pixman
xorg . xorgproto
zlib
2024-10-20 22:55:34 -04:00
(
2025-05-12 03:51:57 +02:00
if ( lib . versionAtLeast version " 1 2 9 " ) then nss_latest else nss_esr # 3.90
2024-10-20 22:55:34 -04:00
)
]
++ lib . optional alsaSupport alsa-lib
++ lib . optional jackSupport libjack2
++ lib . optional pulseaudioSupport libpulseaudio # only headers are needed
++ lib . optional sndioSupport sndio
++ lib . optionals waylandSupport [
libxkbcommon
libdrm
]
) )
2025-05-12 03:49:34 +02:00
++ [ ( if ( lib . versionAtLeast version " 1 3 8 " ) then icu77 else icu73 ) ]
2022-03-21 20:09:59 +01:00
++ lib . optional gssSupport libkrb5
++ lib . optional jemallocSupport jemalloc
++ extraBuildInputs ;
2022-03-22 03:35:51 +01:00
profilingPhase = lib . optionalString pgoSupport ''
# Package up Firefox for profiling
./mach package
# Run profiling
(
export HOME = $ TMPDIR
export LLVM_PROFDATA = llvm-profdata
export JARLOG_FILE = " $ T M P D I R / j a r l o g "
xvfb-run - w 10 - s " - s c r e e n 0 1 9 2 0 x 1 0 8 0 x 2 4 " \
./mach python ./build/pgo/profileserver.py
)
# Copy profiling data to a place we can easily reference
cp ./merged.profdata $ TMPDIR/merged.profdata
# Clean build dir
./mach clobber
'' ;
2022-03-21 20:09:59 +01:00
preBuild = ''
2024-04-28 16:13:25 +02:00
cd objdir
2018-02-01 00:00:00 +00:00
'' ;
2022-03-22 03:35:51 +01:00
postBuild = ''
cd . .
'' ;
2021-11-16 18:40:02 +08:00
makeFlags = extraMakeFlags ;
2022-03-21 20:09:59 +01:00
separateDebugInfo = enableDebugSymbols ;
2014-07-23 15:31:49 +02:00
enableParallelBuilding = true ;
2022-08-15 11:50:26 +02:00
env = lib . optionalAttrs stdenv . hostPlatform . isMusl {
# Firefox relies on nonstandard behavior of the glibc dynamic linker. It re-uses
# previously loaded libraries even though they are not in the rpath of the newly loaded binary.
2025-02-22 21:23:34 +01:00
# On musl we have to explicitly set the rpath to include these libraries.
2022-08-15 11:50:26 +02:00
LDFLAGS = " - W l , - r p a t h , ${ placeholder " o u t " } / l i b / ${ binaryName } " ;
} ;
2022-03-21 20:09:59 +01:00
# tests were disabled in configureFlags
doCheck = false ;
2014-07-23 15:31:49 +02:00
2022-05-12 14:40:21 +02:00
# Generate build symbols once after the final build
# https://firefox-source-docs.mozilla.org/crash-reporting/uploading_symbol.html
2022-05-16 13:52:15 -07:00
preInstall =
lib . optionalString crashreporterSupport ''
2022-05-12 14:40:21 +02:00
./mach buildsymbols
mkdir - p $ symbols /
2024-04-28 16:13:25 +02:00
cp objdir/dist /* . c r a s h r e p o r t e r - s y m b o l s . z i p $ s y m b o l s /
2022-05-16 13:52:15 -07:00
''
+ ''
2024-04-28 16:13:25 +02:00
cd objdir
2022-03-22 03:35:51 +01:00
'' ;
2024-10-20 22:55:34 -04:00
# The target will prepare .app bundle
installTargets = lib . optionalString stdenv . hostPlatform . isDarwin " s t a g e - p a c k a g e " ;
postInstall =
lib . optionalString stdenv . hostPlatform . isDarwin ''
mkdir - p $ out/Applications
2025-01-29 20:35:46 -05:00
cp - r dist / $ { binaryName } /* . a p p " $ o u t / A p p l i c a t i o n s / $ { a p p l i c a t i o n N a m e } . a p p "
2022-05-16 00:26:57 +02:00
2025-01-29 20:35:46 -05:00
resourceDir = " $ o u t / A p p l i c a t i o n s / ${ applicationName } . a p p / C o n t e n t s / R e s o u r c e s "
2024-10-20 22:55:34 -04:00
''
+ lib . optionalString ( ! stdenv . hostPlatform . isDarwin ) ''
2017-03-27 12:33:00 +00:00
# Remove SDK cruft. FIXME: move to a separate output?
2019-01-01 00:00:00 +00:00
rm - rf $ out/share/idl $ out/include $ out/lib / $ { binaryName } - devel- *
2017-03-27 12:33:00 +00:00
# Needed to find Mozilla runtime
2019-01-01 00:00:00 +00:00
gappsWrapperArgs + = ( - - argv0 " $ o u t / b i n / . ${ binaryName } - w r a p p e d " )
2024-10-20 22:55:34 -04:00
resourceDir = $ out/lib / $ { binaryName }
''
+ ''
# Install distribution customizations
install - Dvm644 $ { distributionIni } " $ r e s o u r c e D i r / d i s t r i b u t i o n / d i s t r i b u t i o n . i n i "
install - Dvm644 $ { defaultPrefsFile } " $ r e s o u r c e D i r / b r o w s e r / d e f a u l t s / p r e f e r e n c e s / n i x o s - d e f a u l t - p r e f s . j s "
cd . .
2017-03-27 12:33:00 +00:00
'' ;
2024-10-20 22:55:34 -04:00
postFixup = lib . optionalString ( crashreporterSupport && buildStdenv . hostPlatform . isLinux ) ''
2022-11-08 00:02:25 +01:00
patchelf - - add-rpath " ${ lib . makeLibraryPath [ curl ] } " $ out/lib / $ { binaryName } /crashreporter
'' ;
2024-10-20 22:55:34 -04:00
# Some basic testing
2017-04-09 20:17:40 +03:00
doInstallCheck = true ;
2024-10-20 22:55:34 -04:00
installCheckPhase =
lib . optionalString buildStdenv . hostPlatform . isDarwin ''
2025-01-29 20:35:46 -05:00
bindir = " $ o u t / A p p l i c a t i o n s / ${ applicationName } . a p p / C o n t e n t s / M a c O S "
2024-10-20 22:55:34 -04:00
''
+ lib . optionalString ( ! buildStdenv . hostPlatform . isDarwin ) ''
bindir = $ out/bin
''
+ ''
" $ b i n d i r / ${ binaryName } " - - version
2017-03-27 12:33:00 +00:00
'' ;
2013-06-06 13:07:54 +02:00
2014-07-23 15:31:49 +02:00
passthru = {
2025-01-29 20:35:46 -05:00
inherit applicationName ;
2023-02-24 11:46:48 +01:00
inherit application extraPatches ;
2020-02-01 18:56:13 +01:00
inherit updateScript ;
2020-10-21 21:47:30 -04:00
inherit alsaSupport ;
2022-03-21 16:03:59 +01:00
inherit binaryName ;
2023-11-25 01:53:53 -05:00
inherit requireSigning allowAddonSideload ;
2022-05-07 18:31:10 -04:00
inherit jackSupport ;
2020-12-09 21:26:58 -05:00
inherit pipewireSupport ;
2022-05-07 18:31:10 -04:00
inherit sndioSupport ;
2017-03-27 12:33:00 +00:00
inherit nspr ;
inherit ffmpegSupport ;
2017-09-27 13:30:29 +00:00
inherit gssSupport ;
2020-12-30 21:47:54 -05:00
inherit tests ;
2021-07-12 15:38:03 +02:00
inherit gtk3 ;
2022-03-09 19:40:08 +01:00
inherit wasiSysRoot ;
2023-10-10 17:35:11 +02:00
version = packageVersion ;
2022-02-11 10:05:45 -08:00
} // extraPassthru ;
2020-09-10 02:06:07 +02:00
2020-03-12 14:47:56 +01:00
hardeningDisable = [ " f o r m a t " ] ; # -Werror=format-security
2020-02-01 18:56:13 +01:00
2020-09-10 02:06:07 +02:00
# the build system verifies checksums of the bundled rust sources
# ./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.
# See https://github.com/NixOS/nixpkgs/issues/77289 for more details
2020-01-08 23:14:50 +01:00
# 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
# fetch the sources. Any further modifications of the source tree
# is on purpose by some of our tool (or by accident and a bug?).
2020-01-07 18:40:56 +01:00
dontFixLibtool = true ;
2020-01-08 23:14:50 +01:00
# on aarch64 this is also required
dontUpdateAutotoolsGnuConfigScripts = true ;
2020-11-29 10:28:24 +01:00
requiredSystemFeatures = [ " b i g - p a r a l l e l " ] ;
2023-06-22 19:04:37 -04:00
}