1{
2 lib,
3 stdenv,
4 fetchurl,
5 config,
6 wrapGAppsHook3,
7 autoPatchelfHook,
8 alsa-lib,
9 curl,
10 dbus-glib,
11 gtk3,
12 libXtst,
13 libva,
14 pciutils,
15 pipewire,
16 adwaita-icon-theme,
17 generated,
18 writeScript,
19 writeText,
20 xidel,
21 coreutils,
22 gnused,
23 gnugrep,
24 gnupg,
25 runtimeShell,
26 systemLocale ? config.i18n.defaultLocale or "en_US",
27 patchelfUnstable, # have to use patchelfUnstable to support --no-clobber-old-sections
28 applicationName ? "Firefox",
29 undmg,
30}:
31
32let
33
34 inherit (generated) version sources;
35
36 binaryName = "firefox";
37
38 mozillaPlatforms = {
39 i686-linux = "linux-i686";
40 x86_64-linux = "linux-x86_64";
41 aarch64-linux = "linux-aarch64";
42 # bundles are universal and can be re-used for both darwin architectures
43 aarch64-darwin = "mac";
44 x86_64-darwin = "mac";
45 };
46
47 arch = mozillaPlatforms.${stdenv.hostPlatform.system};
48
49 isPrefixOf = prefix: string: builtins.substring 0 (builtins.stringLength prefix) string == prefix;
50
51 sourceMatches = locale: source: (isPrefixOf source.locale locale) && source.arch == arch;
52
53 policies = {
54 DisableAppUpdate = true;
55 }
56 // config.firefox.policies or { };
57
58 policiesJson = writeText "firefox-policies.json" (builtins.toJSON { inherit policies; });
59
60 defaultSource = lib.findFirst (sourceMatches "en-US") { } sources;
61
62 mozLocale =
63 if systemLocale == "ca_ES@valencia" then
64 "ca-valencia"
65 else
66 lib.replaceStrings [ "_" ] [ "-" ] systemLocale;
67
68 source = lib.findFirst (sourceMatches mozLocale) defaultSource sources;
69
70 pname = "firefox-bin-unwrapped";
71in
72
73stdenv.mkDerivation {
74 inherit pname version;
75
76 src = fetchurl { inherit (source) url sha256; };
77
78 sourceRoot = lib.optional stdenv.hostPlatform.isDarwin ".";
79
80 nativeBuildInputs = [
81 wrapGAppsHook3
82 ]
83 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
84 autoPatchelfHook
85 patchelfUnstable
86 ]
87 ++ lib.optionals stdenv.hostPlatform.isDarwin [
88 undmg
89 ];
90 buildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [
91 gtk3
92 adwaita-icon-theme
93 alsa-lib
94 dbus-glib
95 libXtst
96 ];
97 runtimeDependencies = [
98 curl
99 pciutils
100 ]
101 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
102 libva.out
103 ];
104 appendRunpaths = lib.optionals (!stdenv.hostPlatform.isDarwin) [
105 "${pipewire}/lib"
106 ];
107 # Firefox uses "relrhack" to manually process relocations from a fixed offset
108 patchelfFlags = [ "--no-clobber-old-sections" ];
109
110 # don't break code signing
111 dontFixup = stdenv.hostPlatform.isDarwin;
112
113 installPhase =
114 if stdenv.hostPlatform.isDarwin then
115 ''
116 mkdir -p $out/Applications
117 mv Firefox*.app "$out/Applications/${applicationName}.app"
118 ''
119 else
120 ''
121 mkdir -p "$prefix/lib/firefox-bin-${version}"
122 cp -r * "$prefix/lib/firefox-bin-${version}"
123
124 mkdir -p "$out/bin"
125 ln -s "$prefix/lib/firefox-bin-${version}/firefox" "$out/bin/${binaryName}"
126
127 # See: https://github.com/mozilla/policy-templates/blob/master/README.md
128 mkdir -p "$out/lib/firefox-bin-${version}/distribution";
129 ln -s ${policiesJson} "$out/lib/firefox-bin-${version}/distribution/policies.json";
130 '';
131
132 passthru = {
133 inherit applicationName binaryName;
134 libName = "firefox-bin-${version}";
135 ffmpegSupport = true;
136 gssSupport = true;
137 gtk3 = gtk3;
138
139 # update with:
140 # $ nix-shell maintainers/scripts/update.nix --argstr package firefox-bin-unwrapped
141 updateScript = import ./update.nix {
142 inherit
143 pname
144 writeScript
145 xidel
146 coreutils
147 gnused
148 gnugrep
149 gnupg
150 curl
151 runtimeShell
152 ;
153 baseUrl = "https://archive.mozilla.org/pub/firefox/releases/";
154 };
155 };
156
157 meta = {
158 changelog = "https://www.mozilla.org/en-US/firefox/${version}/releasenotes/";
159 description = "Mozilla Firefox, free web browser (binary package)";
160 homepage = "https://www.mozilla.org/firefox/";
161 license = {
162 shortName = "firefox";
163 fullName = "Firefox Terms of Use";
164 url = "https://www.mozilla.org/about/legal/terms/firefox/";
165 # "You Are Responsible for the Consequences of Your Use of Firefox"
166 # (despite the heading, not an indemnity clause) states the following:
167 #
168 # > You agree that you will not use Firefox to infringe anyone’s rights
169 # > or violate any applicable laws or regulations.
170 # >
171 # > You will not do anything that interferes with or disrupts Mozilla’s
172 # > services or products (or the servers and networks which are connected
173 # > to Mozilla’s services).
174 #
175 # This conflicts with FSF freedom 0: "The freedom to run the program as
176 # you wish, for any purpose". (Why should Mozilla be involved in
177 # instances where you break your local laws just because you happen to
178 # use Firefox whilst doing it?)
179 free = false;
180 redistributable = true; # since MPL-2.0 still applies
181 };
182 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
183 platforms = builtins.attrNames mozillaPlatforms;
184 hydraPlatforms = [ ];
185 maintainers = with lib.maintainers; [
186 taku0
187 lovesegfault
188 ];
189 mainProgram = binaryName;
190 };
191}