1{
2 pname,
3 version,
4 packageVersion ? version,
5 meta,
6 updateScript ? null,
7 binaryName ? "firefox",
8 application ? "browser",
9 applicationName ? "Firefox",
10 branding ? null,
11 requireSigning ? true,
12 allowAddonSideload ? false,
13 src,
14 unpackPhase ? null,
15 extraPatches ? [ ],
16 extraPostPatch ? "",
17 extraNativeBuildInputs ? [ ],
18 extraConfigureFlags ? [ ],
19 extraBuildInputs ? [ ],
20 extraMakeFlags ? [ ],
21 extraPassthru ? { },
22 tests ? { },
23}:
24
25let
26 # Rename the variables to prevent infinite recursion
27 requireSigningDefault = requireSigning;
28 allowAddonSideloadDefault = allowAddonSideload;
29
30 # 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`
31 # This is declared here because it's used in the default value of elfhackSupport
32 isElfhackPlatform =
33 stdenv:
34 stdenv.hostPlatform.isElf
35 && (
36 stdenv.hostPlatform.isi686
37 || stdenv.hostPlatform.isx86_64
38 || stdenv.hostPlatform.isAarch32
39 || stdenv.hostPlatform.isAarch64
40 );
41in
42
43{
44 lib,
45 pkgs,
46 stdenv,
47 patchelf,
48
49 # build time
50 autoconf,
51 cargo,
52 dump_syms,
53 makeWrapper,
54 mimalloc,
55 nodejs,
56 perl,
57 pkg-config,
58 pkgsCross, # wasm32 rlbox
59 python3,
60 runCommand,
61 rustc,
62 rust-cbindgen,
63 rustPlatform,
64 unzip,
65 which,
66 wrapGAppsHook3,
67
68 # runtime
69 bzip2,
70 dbus,
71 dbus-glib,
72 file,
73 fontconfig,
74 freetype,
75 glib,
76 gnum4,
77 gtk3,
78 icu73,
79 icu77, # if you fiddle with the icu parameters, please check Thunderbird's overrides
80 libGL,
81 libGLU,
82 libevent,
83 libffi,
84 libjpeg,
85 libpng,
86 libstartup_notification,
87 libvpx,
88 libwebp,
89 nasm,
90 nspr,
91 nss_esr,
92 nss_3_114,
93 nss_3_115,
94 nss_latest,
95 onnxruntime,
96 pango,
97 xorg,
98 zip,
99 zlib,
100 pkgsBuildBuild,
101
102 # Darwin
103 apple-sdk_14,
104 apple-sdk_15,
105 cups,
106 rsync, # used when preparing .app directory
107
108 # optionals
109
110 ## addon signing/sideloading
111 requireSigning ? requireSigningDefault,
112 allowAddonSideload ? allowAddonSideloadDefault,
113
114 ## debugging
115
116 debugBuild ? false,
117
118 # On 32bit platforms, we disable adding "-g" for easier linking.
119 enableDebugSymbols ? !stdenv.hostPlatform.is32bit,
120
121 ## optional libraries
122
123 alsaSupport ? stdenv.hostPlatform.isLinux,
124 alsa-lib,
125 ffmpegSupport ? true,
126 gssSupport ? true,
127 libkrb5,
128 jackSupport ? stdenv.hostPlatform.isLinux,
129 libjack2,
130 jemallocSupport ? !stdenv.hostPlatform.isMusl,
131 jemalloc,
132 ltoSupport ? (
133 stdenv.hostPlatform.isLinux && stdenv.hostPlatform.is64bit && !stdenv.hostPlatform.isRiscV
134 ),
135 overrideCC,
136 buildPackages,
137 pgoSupport ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform == stdenv.buildPlatform),
138 xvfb-run,
139 elfhackSupport ?
140 isElfhackPlatform stdenv && !(stdenv.hostPlatform.isMusl && stdenv.hostPlatform.isAarch64),
141 pipewireSupport ? waylandSupport && webrtcSupport,
142 pulseaudioSupport ? stdenv.hostPlatform.isLinux,
143 libpulseaudio,
144 sndioSupport ? stdenv.hostPlatform.isLinux,
145 sndio,
146 waylandSupport ? !stdenv.hostPlatform.isDarwin,
147 libxkbcommon,
148 libdrm,
149
150 ## privacy-related options
151
152 privacySupport ? false,
153
154 # WARNING: NEVER set any of the options below to `true` by default.
155 # Set to `!privacySupport` or `false`.
156
157 crashreporterSupport ?
158 !privacySupport
159 && !stdenv.hostPlatform.isLoongArch64
160 && !stdenv.hostPlatform.isRiscV
161 && !stdenv.hostPlatform.isMusl,
162 curl,
163 geolocationSupport ? !privacySupport,
164 webrtcSupport ? !privacySupport,
165
166 # digital rights managemewnt
167
168 # This flag controls whether Firefox will show the nagbar, that allows
169 # users at runtime the choice to enable Widevine CDM support when a site
170 # requests it.
171 # Controlling the nagbar and widevine CDM at runtime is possible by setting
172 # `browser.eme.ui.enabled` and `media.gmp-widevinecdm.enabled` accordingly
173 drmSupport ? true,
174
175 # As stated by Sylvestre Ledru (@sylvestre) on Nov 22, 2017 at
176 # https://github.com/NixOS/nixpkgs/issues/31843#issuecomment-346372756 we
177 # have permission to use the official firefox branding.
178 #
179 # For purposes of documentation the statement of @sylvestre:
180 # > As the person who did part of the work described in the LWN article
181 # > and release manager working for Mozilla, I can confirm the statement
182 # > that I made in
183 # > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815006
184 # >
185 # > @garbas shared with me the list of patches applied for the Nix package.
186 # > As they are just for portability and tiny modifications, they don't
187 # > alter the experience of the product. In parallel, Rok also shared the
188 # > build options. They seem good (even if I cannot judge the quality of the
189 # > packaging of the underlying dependencies like sqlite, png, etc).
190 # > Therefor, as long as you keep the patch queue sane and you don't alter
191 # > the experience of Firefox users, you won't have any issues using the
192 # > official branding.
193 enableOfficialBranding ? true,
194}:
195
196assert stdenv.cc.libc or null != null;
197assert
198 pipewireSupport
199 -> !waylandSupport || !webrtcSupport
200 -> throw "${pname}: pipewireSupport requires both wayland and webrtc support.";
201assert elfhackSupport -> isElfhackPlatform stdenv;
202
203let
204 inherit (lib) enableFeature;
205
206 # Target the LLVM version that rustc is built with for LTO.
207 llvmPackages0 = rustc.llvmPackages;
208 llvmPackagesBuildBuild0 = pkgsBuildBuild.rustc.llvmPackages;
209
210 # Force the use of lld and other llvm tools for LTO
211 llvmPackages = llvmPackages0.override {
212 bootBintoolsNoLibc = null;
213 bootBintools = null;
214 };
215 llvmPackagesBuildBuild = llvmPackagesBuildBuild0.override {
216 bootBintoolsNoLibc = null;
217 bootBintools = null;
218 };
219
220 # LTO requires LLVM bintools including ld.lld and llvm-ar.
221 buildStdenv = overrideCC llvmPackages.stdenv (
222 llvmPackages.stdenv.cc.override {
223 bintools = if ltoSupport then buildPackages.rustc.llvmPackages.bintools else stdenv.cc.bintools;
224 }
225 );
226
227 # Compile the wasm32 sysroot to build the RLBox Sandbox
228 # https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/
229 # We only link c++ libs here, our compiler wrapper can find wasi libc and crt itself.
230 wasiSysRoot = runCommand "wasi-sysroot" { } ''
231 mkdir -p $out/lib/wasm32-wasi
232 for lib in ${pkgsCross.wasi32.llvmPackages.libcxx}/lib/*; do
233 ln -s $lib $out/lib/wasm32-wasi
234 done
235 '';
236
237 distributionIni =
238 let
239 platform = if stdenv.hostPlatform.isDarwin then "Nix on MacOS" else "NixOS";
240 in
241 pkgs.writeText "distribution.ini" (
242 lib.generators.toINI { } {
243 # Some light branding indicating this build uses our distro preferences
244 Global = {
245 id = "nixos";
246 version = "1.0";
247 about = "${applicationName} for ${platform}";
248 };
249 Preferences = {
250 # These values are exposed through telemetry
251 "app.distributor" = "nixos";
252 "app.distributor.channel" = "nixpkgs";
253 };
254 }
255 );
256
257 defaultPrefs =
258 if geolocationSupport then
259 {
260 "geo.provider.network.url" = {
261 value = "https://api.beacondb.net/v1/geolocate";
262 reason = "We have no Google API keys and Mozilla Location Services were retired.";
263 };
264 }
265 else
266 {
267 "geo.provider.use_geoclue" = {
268 value = false;
269 reason = "Geolocation support has been disabled through the `geolocationSupport` package attribute.";
270 };
271 };
272
273 defaultPrefsFile = pkgs.writeText "nixos-default-prefs.js" (
274 lib.concatStringsSep "\n" (
275 lib.mapAttrsToList (key: value: ''
276 // ${value.reason}
277 pref("${key}", ${builtins.toJSON value.value});
278 '') defaultPrefs
279 )
280 );
281
282 toolkit =
283 if stdenv.hostPlatform.isDarwin then
284 "cairo-cocoa"
285 else
286 "cairo-gtk3${lib.optionalString waylandSupport "-wayland"}";
287
288in
289
290buildStdenv.mkDerivation {
291 pname = "${pname}-unwrapped";
292 version = packageVersion;
293
294 inherit src unpackPhase meta;
295
296 outputs = [
297 "out"
298 ]
299 ++ lib.optionals crashreporterSupport [ "symbols" ];
300
301 # Add another configure-build-profiling run before the final configure phase if we build with pgo
302 preConfigurePhases = lib.optionals pgoSupport [
303 "configurePhase"
304 "buildPhase"
305 "profilingPhase"
306 ];
307
308 patches =
309 # Remove references to the build clsoure
310 lib.optionals (lib.versionAtLeast version "136") [ ./136-no-buildconfig.patch ]
311 # Add MOZ_SYSTEM_DIR env var for native messaging host support
312 ++ lib.optionals (lib.versionAtLeast version "133") [ ./133-env-var-for-system-dir.patch ]
313 ++ lib.optionals (lib.versionAtLeast version "139" && lib.versionOlder version "141") [
314 # https://bugzilla.mozilla.org/show_bug.cgi?id=1955112
315 # https://hg-edge.mozilla.org/mozilla-central/rev/aa8a29bd1fb9
316 ./139-wayland-drag-animation.patch
317 ]
318 ++
319 lib.optionals
320 (
321 lib.versionAtLeast version "141.0.2"
322 || (lib.versionAtLeast version "140.2.0" && lib.versionOlder version "141.0")
323 )
324 [
325 ./142-relax-apple-sdk.patch
326 ]
327 ++ extraPatches;
328
329 postPatch = ''
330 rm -rf obj-x86_64-pc-linux-gnu
331 patchShebangs mach build
332 ''
333 # https://bugzilla.mozilla.org/show_bug.cgi?id=1927380
334 + lib.optionalString (lib.versionAtLeast version "134") ''
335 sed -i "s/icu-i18n/icu-uc &/" js/moz.configure
336 ''
337 + extraPostPatch;
338
339 # Ignore trivial whitespace changes in patches, this fixes compatibility of
340 # ./env_var_for_system_dir-*.patch with Firefox >=65 without having to track
341 # two patches.
342 patchFlags = [
343 "-p1"
344 "-l"
345 ];
346
347 # if not explicitly set, wrong cc from buildStdenv would be used
348 HOST_CC = "${llvmPackagesBuildBuild.stdenv.cc}/bin/cc";
349 HOST_CXX = "${llvmPackagesBuildBuild.stdenv.cc}/bin/c++";
350
351 nativeBuildInputs = [
352 autoconf
353 cargo
354 gnum4
355 llvmPackagesBuildBuild.bintools
356 makeWrapper
357 nodejs
358 perl
359 python3
360 rust-cbindgen
361 rustPlatform.bindgenHook
362 rustc
363 unzip
364 which
365 wrapGAppsHook3
366 ]
367 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ pkg-config ]
368 ++ lib.optionals stdenv.hostPlatform.isDarwin [ rsync ]
369 ++ lib.optionals stdenv.hostPlatform.isx86 [ nasm ]
370 ++ lib.optionals crashreporterSupport [
371 dump_syms
372 patchelf
373 ]
374 ++ lib.optionals pgoSupport [ xvfb-run ]
375 ++ extraNativeBuildInputs;
376
377 setOutputFlags = false; # `./mach configure` doesn't understand `--*dir=` flags.
378
379 preConfigure = ''
380 # Runs autoconf through ./mach configure in configurePhase
381 configureScript="$(realpath ./mach) configure"
382
383 # Set reproducible build date; https://bugzilla.mozilla.org/show_bug.cgi?id=885777#c21
384 export MOZ_BUILD_DATE=$(head -n1 sourcestamp.txt)
385
386 # Set predictable directories for build and state
387 export MOZ_OBJDIR=$(pwd)/objdir
388 export MOZBUILD_STATE_PATH=$TMPDIR/mozbuild
389
390 # Don't try to send libnotify notifications during build
391 export MOZ_NOSPAM=1
392
393 # Set consistent remoting name to ensure wmclass matches with desktop file
394 export MOZ_APP_REMOTINGNAME="${binaryName}"
395
396 # AS=as in the environment causes build failure
397 # https://bugzilla.mozilla.org/show_bug.cgi?id=1497286
398 unset AS
399
400 # Use our own python
401 export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system
402
403 # RBox WASM Sandboxing
404 export WASM_CC=${pkgsCross.wasi32.stdenv.cc}/bin/${pkgsCross.wasi32.stdenv.cc.targetPrefix}cc
405 export WASM_CXX=${pkgsCross.wasi32.stdenv.cc}/bin/${pkgsCross.wasi32.stdenv.cc.targetPrefix}c++
406 ''
407 + lib.optionalString pgoSupport ''
408 if [ -e "$TMPDIR/merged.profdata" ]; then
409 echo "Configuring with profiling data"
410 for i in "''${!configureFlagsArray[@]}"; do
411 if [[ ''${configureFlagsArray[i]} = "--enable-profile-generate=cross" ]]; then
412 unset 'configureFlagsArray[i]'
413 fi
414 done
415 appendToVar configureFlags --enable-profile-use=cross
416 appendToVar configureFlags --with-pgo-profile-path=$TMPDIR/merged.profdata
417 appendToVar configureFlags --with-pgo-jarlog=$TMPDIR/jarlog
418 ${lib.optionalString stdenv.hostPlatform.isMusl ''
419 LDFLAGS="$OLD_LDFLAGS"
420 unset OLD_LDFLAGS
421 ''}
422 else
423 echo "Configuring to generate profiling data"
424 configureFlagsArray+=(
425 "--enable-profile-generate=cross"
426 )
427 ${lib.optionalString stdenv.hostPlatform.isMusl
428 # Set the rpath appropriately for the profiling run
429 # During the profiling run, loading libraries from $out would fail,
430 # since the profiling build has not been installed to $out
431 ''
432 OLD_LDFLAGS="$LDFLAGS"
433 LDFLAGS="-Wl,-rpath,$(pwd)/objdir/dist/${binaryName}"
434 ''
435 }
436 fi
437 ''
438 + lib.optionalString (enableOfficialBranding && !stdenv.hostPlatform.is32bit) ''
439 export MOZILLA_OFFICIAL=1
440 ''
441 + lib.optionalString (!requireSigning) ''
442 export MOZ_REQUIRE_SIGNING=
443 ''
444 + lib.optionalString stdenv.hostPlatform.isMusl ''
445 # linking firefox hits the vm.max_map_count kernel limit with the default musl allocator
446 # TODO: Default vm.max_map_count has been increased, retest without this
447 export LD_PRELOAD=${mimalloc}/lib/libmimalloc.so
448 ''
449 +
450 # fileport.h was exposed in SDK 15.4 but we have only 15.2 in nixpkgs so far.
451 lib.optionalString
452 (
453 stdenv.hostPlatform.isDarwin
454 && lib.versionAtLeast version "143"
455 && lib.versionOlder apple-sdk_15.version "15.4"
456 )
457 ''
458 mkdir -p xnu/sys
459 cp ${apple-sdk_15.sourceRelease "xnu"}/bsd/sys/fileport.h xnu/sys
460 export CXXFLAGS="-isystem $(pwd)/xnu"
461 '';
462
463 # firefox has a different definition of configurePlatforms from nixpkgs, see configureFlags
464 configurePlatforms = [ ];
465
466 configureFlags = [
467 "--disable-tests"
468 "--disable-updater"
469 "--enable-application=${application}"
470 "--enable-default-toolkit=${toolkit}"
471 "--with-app-name=${binaryName}"
472 "--with-distribution-id=org.nixos"
473 "--with-libclang-path=${lib.getLib llvmPackagesBuildBuild.libclang}/lib"
474 "--with-wasi-sysroot=${wasiSysRoot}"
475 # for firefox, host is buildPlatform, target is hostPlatform
476 "--host=${buildStdenv.buildPlatform.config}"
477 "--target=${buildStdenv.hostPlatform.config}"
478 ]
479 # LTO is done using clang and lld on Linux.
480 ++ lib.optionals ltoSupport [
481 "--enable-lto=cross,full" # Cross-Language LTO
482 "--enable-linker=lld"
483 ]
484 ++ lib.optional (isElfhackPlatform stdenv) (enableFeature elfhackSupport "elf-hack")
485 ++ lib.optional (!drmSupport) "--disable-eme"
486 ++ lib.optional allowAddonSideload "--allow-addon-sideload"
487 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
488 # MacOS builds use bundled versions of libraries: https://bugzilla.mozilla.org/show_bug.cgi?id=1776255
489 "--enable-system-pixman"
490 "--with-system-ffi"
491 "--with-system-icu"
492 "--with-system-jpeg"
493 "--with-system-libevent"
494 "--with-system-libvpx"
495 "--with-system-nspr"
496 "--with-system-nss"
497 "--with-system-png" # needs APNG support
498 "--with-system-webp"
499 "--with-system-zlib"
500
501 # These options are not available on MacOS, even --disable-*
502 (enableFeature alsaSupport "alsa")
503 (enableFeature jackSupport "jack")
504 (enableFeature pulseaudioSupport "pulseaudio")
505 (enableFeature sndioSupport "sndio")
506 ]
507 ++ lib.optionals (!buildStdenv.hostPlatform.isDarwin && lib.versionAtLeast version "141") [
508 "--with-onnx-runtime=${lib.getLib onnxruntime}/lib"
509 ]
510 ++ [
511 (enableFeature crashreporterSupport "crashreporter")
512 (enableFeature ffmpegSupport "ffmpeg")
513 (enableFeature geolocationSupport "necko-wifi")
514 (enableFeature gssSupport "negotiateauth")
515 (enableFeature jemallocSupport "jemalloc")
516 (enableFeature webrtcSupport "webrtc")
517
518 (enableFeature debugBuild "debug")
519 (if debugBuild then "--enable-profiling" else "--enable-optimize")
520 # --enable-release adds -ffunction-sections & LTO that require a big amount
521 # of RAM, and the 32-bit memory space cannot handle that linking
522 (enableFeature (!debugBuild && !stdenv.hostPlatform.is32bit) "release")
523 (enableFeature enableDebugSymbols "debug-symbols")
524 ]
525 ++ lib.optionals enableDebugSymbols [
526 "--disable-strip"
527 "--disable-install-strip"
528 ]
529 # As of Firefox 137 (https://bugzilla.mozilla.org/show_bug.cgi?id=1943009),
530 # the --enable-official-branding flag overrides the --with-branding flag.
531 ++ lib.optional (enableOfficialBranding && branding == null) "--enable-official-branding"
532 ++ lib.optional (branding != null) "--with-branding=${branding}"
533 ++ extraConfigureFlags;
534
535 buildInputs = [
536 bzip2
537 file
538 libGL
539 libGLU
540 libstartup_notification
541 perl
542 zip
543 ]
544 ++ lib.optionals stdenv.hostPlatform.isDarwin [
545 (if lib.versionAtLeast version "138" then apple-sdk_15 else apple-sdk_14)
546 cups
547 ]
548 ++ (lib.optionals (!stdenv.hostPlatform.isDarwin) (
549 [
550 dbus
551 dbus-glib
552 fontconfig
553 freetype
554 glib
555 gtk3
556 libffi
557 libevent
558 libjpeg
559 libpng
560 libvpx
561 libwebp
562 nspr
563 pango
564 xorg.libX11
565 xorg.libXcursor
566 xorg.libXdamage
567 xorg.libXext
568 xorg.libXft
569 xorg.libXi
570 xorg.libXrender
571 xorg.libXt
572 xorg.libXtst
573 xorg.pixman
574 xorg.xorgproto
575 zlib
576 (
577 if (lib.versionAtLeast version "144") then
578 nss_latest
579 else if (lib.versionAtLeast version "143") then
580 nss_3_115
581 else if (lib.versionAtLeast version "141") then
582 nss_3_114
583 else
584 nss_esr
585 )
586 ]
587 ++ lib.optional alsaSupport alsa-lib
588 ++ lib.optional jackSupport libjack2
589 ++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed
590 ++ lib.optional sndioSupport sndio
591 ++ lib.optionals waylandSupport [
592 libxkbcommon
593 libdrm
594 ]
595 ))
596 ++ [ (if (lib.versionAtLeast version "138") then icu77 else icu73) ]
597 ++ lib.optional gssSupport libkrb5
598 ++ lib.optional jemallocSupport jemalloc
599 ++ extraBuildInputs;
600
601 profilingPhase = lib.optionalString pgoSupport ''
602 # Avoid compressing the instrumented build with high levels of compression
603 export MOZ_PKG_FORMAT=tar
604
605 # Package up Firefox for profiling
606 ./mach package
607
608 # Run profiling
609 (
610 export HOME=$TMPDIR
611 export LLVM_PROFDATA=llvm-profdata
612 export JARLOG_FILE="$TMPDIR/jarlog"
613
614 xvfb-run -w 10 -s "-screen 0 1920x1080x24" \
615 ./mach python ./build/pgo/profileserver.py
616 )
617
618 # Copy profiling data to a place we can easily reference
619 cp ./merged.profdata $TMPDIR/merged.profdata
620
621 # Clean build dir
622 ./mach clobber
623 '';
624
625 preBuild = ''
626 cd objdir
627 '';
628
629 postBuild = ''
630 cd ..
631 '';
632
633 makeFlags = extraMakeFlags;
634 separateDebugInfo = enableDebugSymbols;
635 enableParallelBuilding = true;
636 env = lib.optionalAttrs stdenv.hostPlatform.isMusl {
637 # Firefox relies on nonstandard behavior of the glibc dynamic linker. It re-uses
638 # previously loaded libraries even though they are not in the rpath of the newly loaded binary.
639 # On musl we have to explicitly set the rpath to include these libraries.
640 LDFLAGS = "-Wl,-rpath,${placeholder "out"}/lib/${binaryName}";
641 };
642
643 # tests were disabled in configureFlags
644 doCheck = false;
645
646 # Generate build symbols once after the final build
647 # https://firefox-source-docs.mozilla.org/crash-reporting/uploading_symbol.html
648 preInstall =
649 lib.optionalString crashreporterSupport ''
650 ./mach buildsymbols
651 mkdir -p $symbols/
652 cp objdir/dist/*.crashreporter-symbols.zip $symbols/
653 ''
654 + ''
655 cd objdir
656 '';
657
658 # The target will prepare .app bundle
659 installTargets = lib.optionalString stdenv.hostPlatform.isDarwin "stage-package";
660
661 postInstall =
662 lib.optionalString stdenv.hostPlatform.isDarwin ''
663 mkdir -p $out/Applications
664 cp -r dist/${binaryName}/*.app "$out/Applications/${applicationName}.app"
665
666 resourceDir="$out/Applications/${applicationName}.app/Contents/Resources"
667
668 ''
669 + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
670 # Remove SDK cruft. FIXME: move to a separate output?
671 rm -rf $out/share/idl $out/include $out/lib/${binaryName}-devel-*
672
673 # Needed to find Mozilla runtime
674 gappsWrapperArgs+=(--argv0 "$out/bin/.${binaryName}-wrapped")
675
676 resourceDir=$out/lib/${binaryName}
677 ''
678 + ''
679 # Install distribution customizations
680 install -Dvm644 ${distributionIni} "$resourceDir/distribution/distribution.ini"
681 install -Dvm644 ${defaultPrefsFile} "$resourceDir/browser/defaults/preferences/nixos-default-prefs.js"
682
683 cd ..
684 '';
685
686 postFixup = lib.optionalString (crashreporterSupport && buildStdenv.hostPlatform.isLinux) ''
687 patchelf --add-rpath "${lib.makeLibraryPath [ curl ]}" $out/lib/${binaryName}/crashreporter
688 '';
689
690 # Some basic testing
691 doInstallCheck = true;
692 installCheckPhase =
693 lib.optionalString buildStdenv.hostPlatform.isDarwin ''
694 bindir="$out/Applications/${applicationName}.app/Contents/MacOS"
695 ''
696 + lib.optionalString (!buildStdenv.hostPlatform.isDarwin) ''
697 bindir=$out/bin
698 ''
699 + ''
700 "$bindir/${binaryName}" --version
701 '';
702
703 passthru = {
704 inherit applicationName;
705 inherit application extraPatches;
706 inherit updateScript;
707 inherit alsaSupport;
708 inherit binaryName;
709 inherit requireSigning allowAddonSideload;
710 inherit jackSupport;
711 inherit pipewireSupport;
712 inherit sndioSupport;
713 inherit nspr;
714 inherit ffmpegSupport;
715 inherit gssSupport;
716 inherit tests;
717 inherit gtk3;
718 inherit wasiSysRoot;
719 version = packageVersion;
720 }
721 // extraPassthru;
722
723 hardeningDisable = [ "format" ]; # -Werror=format-security
724
725 # the build system verifies checksums of the bundled rust sources
726 # ./third_party/rust is be patched by our libtool fixup code in stdenv
727 # unfortunately we can't just set this to `false` when we do not want it.
728 # See https://github.com/NixOS/nixpkgs/issues/77289 for more details
729 # Ideally we would figure out how to tell the build system to not
730 # care about changed hashes as we are already doing that when we
731 # fetch the sources. Any further modifications of the source tree
732 # is on purpose by some of our tool (or by accident and a bug?).
733 dontFixLibtool = true;
734
735 # on aarch64 this is also required
736 dontUpdateAutotoolsGnuConfigScripts = true;
737
738 requiredSystemFeatures = [ "big-parallel" ];
739}