Skip to content

Commit

Permalink
firefox, thunderbird: enable wrapped derivations for darwin
Browse files Browse the repository at this point in the history
It also aligns application names for wrapped and unwrapped flavors of
the same derivations; and uses unique application names for each flavor,
so it's now possible to install multiple versions on the same Darwin
machine.

One visible change now is that `About Firefox` window now shows:

`Firefox for NixOS` instead of `Mozilla Firefox for NixOS`

...in the `distribution` field. I think it's fine and doesn't infringe
on any trademarks because this field is not required to mention Mozilla at
all, as per: https://wiki.mozilla.org/Distribution_INI_File

While at it, also changed the branding for Darwin builds to list:

`Firefox for Nix on MacOS` instead of `Firefox for NixOS`

The telemetry and distribution ids (`nixos`) are left intact.

Note: it's still not possible to install both source-based and -bin
Darwin derivations in the same profile. It would require renaming
applicationNames for these two different types to use unique names (e.g.
`Firefox (Official)` or `Firefox (Binary)`, which doesn't seem optimal.

Closes: NixOS#378433
Closes: NixOS#366581

Signed-off-by: Ihar Hrachyshka <[email protected]>
  • Loading branch information
booxter committed Feb 1, 2025
1 parent de0e0b0 commit fa0c455
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 46 deletions.
2 changes: 2 additions & 0 deletions pkgs/applications/networking/browsers/firefox-bin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, runtimeShell
, systemLocale ? config.i18n.defaultLocale or "en_US"
, patchelfUnstable # have to use patchelfUnstable to support --no-clobber-old-sections
, applicationName? "Firefox"
}:

let
Expand Down Expand Up @@ -98,6 +99,7 @@ stdenv.mkDerivation {

passthru = {
inherit binaryName;
inherit applicationName;
libName = "firefox-bin-${version}";
ffmpegSupport = true;
gssSupport = true;
Expand Down
20 changes: 11 additions & 9 deletions pkgs/applications/networking/browsers/firefox/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, updateScript ? null
, binaryName ? "firefox"
, application ? "browser"
, applicationName ? "Mozilla Firefox"
, applicationName ? "Firefox"
, branding ? null
, requireSigning ? true
, allowAddonSideload ? false
Expand Down Expand Up @@ -119,7 +119,7 @@ in
, pipewireSupport ? waylandSupport && webrtcSupport
, pulseaudioSupport ? stdenv.hostPlatform.isLinux, libpulseaudio
, sndioSupport ? stdenv.hostPlatform.isLinux, sndio
, waylandSupport ? true, libxkbcommon, libdrm
, waylandSupport ? !stdenv.hostPlatform.isDarwin, libxkbcommon, libdrm

## privacy-related options

Expand Down Expand Up @@ -200,12 +200,15 @@ let
done
'';

distributionIni = pkgs.writeText "distribution.ini" (lib.generators.toINI {} {
distributionIni = let
platform = if stdenv.hostPlatform.isDarwin then "Nix on MacOS" else "NixOS";
in
pkgs.writeText "distribution.ini" (lib.generators.toINI {} {
# Some light branding indicating this build uses our distro preferences
Global = {
id = "nixos";
version = "1.0";
about = "${applicationName} for NixOS";
about = "${applicationName} for ${platform}";
};
Preferences = {
# These values are exposed through telemetry
Expand Down Expand Up @@ -592,11 +595,9 @@ buildStdenv.mkDerivation {

postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
cp -r dist/${binaryName}/*.app $out/Applications
cp -r dist/${binaryName}/*.app "$out/Applications/${applicationName}.app"
appBundlePath=(dist/${binaryName}/*.app)
appBundle=''${appBundlePath[0]#dist/${binaryName}}
resourceDir=$out/Applications/$appBundle/Contents/Resources
resourceDir="$out/Applications/${applicationName}.app/Contents/Resources"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
# Remove SDK cruft. FIXME: move to a separate output?
Expand All @@ -621,14 +622,15 @@ buildStdenv.mkDerivation {
# Some basic testing
doInstallCheck = true;
installCheckPhase = lib.optionalString buildStdenv.hostPlatform.isDarwin ''
bindir=$out/Applications/$appBundle/Contents/MacOS
bindir="$out/Applications/${applicationName}.app/Contents/MacOS"
'' + lib.optionalString (!buildStdenv.hostPlatform.isDarwin) ''
bindir=$out/bin
'' + ''
"$bindir/${binaryName}" --version
'';

passthru = {
inherit applicationName;
inherit application extraPatches;
inherit updateScript;
inherit alsaSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
buildMozillaMach rec {
pname = "firefox-beta";
version = "135.0b9";
applicationName = "Mozilla Firefox Beta";
applicationName = "Firefox Beta";
src = fetchurl {
url = "mirror://mozilla/firefox/releases/${version}/source/firefox-${version}.source.tar.xz";
sha512 = "3007c2a8743e4444226e66f0c11f53f01255c09702deda7de83bbe134a19c324b8b49de78d3211b20bb82c7b2040127145d2e39ed8aa81c653ac4397c46476f6";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
buildMozillaMach rec {
pname = "firefox-devedition";
version = "135.0b9";
applicationName = "Mozilla Firefox Developer Edition";
applicationName = "Firefox Developer Edition";
requireSigning = false;
branding = "browser/branding/aurora";
src = fetchurl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
buildMozillaMach rec {
pname = "firefox";
version = "128.6.0esr";
applicationName = "Firefox ESR";
src = fetchurl {
url = "mirror://mozilla/firefox/releases/${version}/source/firefox-${version}.source.tar.xz";
sha512 = "49bce966e062766861712bd65cca46a438b339fe31598f69e4fe64da78ef6f8b4581c1d502341ef1c032aafaab2f4f88e69cb93a0b845ba7173fec277ae695b5";
Expand Down
85 changes: 60 additions & 25 deletions pkgs/applications/networking/browsers/firefox/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, makeDesktopItem, makeWrapper, makeBinaryWrapper, lndir, config
{ stdenv, lib, makeDesktopItem, makeBinaryWrapper, lndir, config
, buildPackages
, jq, xdg-utils, writeText

Expand Down Expand Up @@ -27,11 +27,9 @@ browser:

let
wrapper =
{ applicationName ? browser.binaryName or (lib.getName browser)
{ applicationName ? browser.binaryName or (lib.getName browser) # Note: this is actually *binary* name and is different from browser.passthru.applicationName, which is *app* name!
, pname ? applicationName
, version ? lib.getVersion browser
, desktopName ? # applicationName with first letter capitalized
(lib.toUpper (lib.substring 0 1 applicationName) + lib.substring 1 (-1) applicationName)
, nameSuffix ? ""
, icon ? applicationName
, wmClass ? applicationName
Expand Down Expand Up @@ -106,7 +104,8 @@ let
++ gtk_modules;
gtk_modules = [ libcanberra-gtk3 ];

launcherName = "${applicationName}${nameSuffix}";
# Darwin does not rename bundled binaries
launcherName = "${applicationName}${lib.optionalString (!stdenv.hostPlatform.isDarwin) nameSuffix}";

#########################
# #
Expand Down Expand Up @@ -188,7 +187,7 @@ let
name = launcherName;
exec = "${launcherName} --name ${wmClass} %U";
inherit icon;
inherit desktopName;
desktopName = browser.passthru.applicationName;
startupNotify = true;
startupWMClass = wmClass;
terminal = false;
Expand Down Expand Up @@ -243,7 +242,7 @@ let
};
}));

nativeBuildInputs = [ makeWrapper lndir jq ];
nativeBuildInputs = [ makeBinaryWrapper lndir jq ];
buildInputs = [ browser.gtk3 ];

makeWrapperArgs = [
Expand Down Expand Up @@ -303,10 +302,17 @@ let
''ln -sfLt ''${MOZ_HOME:-~/.mozilla}/native-messaging-hosts ${ext}/lib/mozilla/native-messaging-hosts/*''
]) allNativeMessagingHosts);

buildCommand = ''
if [ ! -x "${browser}/bin/${applicationName}" ]
buildCommand = lib.optionalString stdenv.hostPlatform.isDarwin ''
executablePrefix="Applications/${browser.passthru.applicationName}.app/Contents/MacOS"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
executablePrefix=bin
'' + ''
executablePath="$executablePrefix/${applicationName}"
sourceBinary="${browser}/$executablePath"
if [ ! -x "$sourceBinary" ]
then
echo "cannot find executable file \`${browser}/bin/${applicationName}'"
echo "cannot find executable file \`$sourceBinary'"
exit 1
fi
Expand All @@ -315,10 +321,11 @@ let
# EXTRA PREF CHANGES #
# #
#########################
cd "${browser}"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
# Link the runtime. The executable itself has to be copied,
# because it will resolve paths relative to its true location.
# Any symbolic links have to be replicated as well.
cd "${browser}"
find . -type d -exec mkdir -p "$out"/{} \;
find . -type f \( -not -name "${applicationName}" \) -exec ln -sT "${browser}"/{} "$out"/{} \;
Expand All @@ -336,14 +343,21 @@ let
ln -sfT "$target" "$out/$l"
done
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
# MacOS bundles are not playing well with symlinks that point outside the bundle.
cp -r . "$out"
'' + ''
cd "$out"
# create the wrapper
executablePrefix="$out/bin"
executablePath="$executablePrefix/${applicationName}"
executablePrefix="$out/$executablePrefix"
executablePath="$out/$executablePath"
oldWrapperArgs=()
chmod +rwx "$executablePrefix"
chmod +rwx "$executablePath"
if [[ -L $executablePath ]]; then
# Symbolic link: wrap the link's target.
oldExe="$(readlink -v --canonicalize-existing "$executablePath")"
Expand Down Expand Up @@ -372,13 +386,20 @@ let
appendToVar makeWrapperArgs --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
concatTo makeWrapperArgs oldWrapperArgs
makeWrapper "$oldExe" "''${executablePath}${nameSuffix}" "''${makeWrapperArgs[@]}"
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
finalBinaryPath="$executablePath"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
finalBinaryPath="''${executablePath}${nameSuffix}"
'' + ''
makeWrapper "$oldExe" "$finalBinaryPath" "''${makeWrapperArgs[@]}"
#############################
# #
# END EXTRA PREF CHANGES #
# #
#############################
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
if [ -e "${browser}/share/icons" ]; then
mkdir -p "$out/share"
ln -s "${browser}/share/icons" "$out/share/icons"
Expand All @@ -395,12 +416,14 @@ let
install -D -t $out/share/applications $desktopItem/share/applications/*
'' + lib.optionalString hasMozSystemDirPatch ''
chmod +rwx "$out"
mkdir -p $out/lib/mozilla/native-messaging-hosts
for ext in ${toString allNativeMessagingHosts}; do
ln -sLt $out/lib/mozilla/native-messaging-hosts $ext/lib/mozilla/native-messaging-hosts/*
done
'' + ''
chmod +rwx "$out"
mkdir -p $out/lib/mozilla/pkcs11-modules
for ext in ${toString pkcs11Modules}; do
ln -sLt $out/lib/mozilla/pkcs11-modules $ext/lib/mozilla/pkcs11-modules/*
Expand All @@ -413,12 +436,17 @@ let
# #
#########################
# user customization
mkdir -p $out/lib/${libName}
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
libDir="$out/lib/${libName}"
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
libDir="$out/Applications/${browser.passthru.applicationName}.app/Contents/Resources"
'' + ''
# creating policies.json
mkdir -p "$out/lib/${libName}/distribution"
mkdir -p "$libDir/distribution"
chmod +rwx "$libDir/distribution"
POL_PATH="$out/lib/${libName}/distribution/policies.json"
POL_PATH="$libDir/distribution/policies.json"
rm -f "$POL_PATH"
cat ${policiesJson} >> "$POL_PATH"
Expand All @@ -429,25 +457,32 @@ let
done
# preparing for autoconfig
mkdir -p "$out/lib/${libName}/defaults/pref"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
prefsDir="$libDir/defaults/pref"
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
prefsDir="$libDir/browser/defaults/preferences"
'' + ''
mkdir -p "$prefsDir"
chmod +rwx "$prefsDir"
echo 'pref("general.config.filename", "mozilla.cfg");' > "$out/lib/${libName}/defaults/pref/autoconfig.js"
echo 'pref("general.config.obscure_value", 0);' >> "$out/lib/${libName}/defaults/pref/autoconfig.js"
echo 'pref("general.config.filename", "mozilla.cfg");' > "$prefsDir/autoconfig.js"
echo 'pref("general.config.obscure_value", 0);' >> "$prefsDir/autoconfig.js"
cat > "$out/lib/${libName}/mozilla.cfg" << EOF
chmod +rwx "$libDir"
cat > "$libDir/mozilla.cfg" << EOF
${mozillaCfg}
EOF
extraPrefsFiles=(${builtins.toString extraPrefsFiles})
for extraPrefsFile in "''${extraPrefsFiles[@]}"; do
cat "$extraPrefsFile" >> "$out/lib/${libName}/mozilla.cfg"
cat "$extraPrefsFile" >> "$libDir/mozilla.cfg"
done
cat >> "$out/lib/${libName}/mozilla.cfg" << EOF
cat >> "$libDir/mozilla.cfg" << EOF
${extraPrefs}
EOF
mkdir -p $out/lib/${libName}/distribution/extensions
mkdir -p "$libDir/distribution/extensions"
#############################
# #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
systemLocale ? config.i18n.defaultLocale or "en_US",
patchelfUnstable, # have to use patchelfUnstable to support --no-clobber-old-sections
generated,
applicationName ? "Thunderbird",
}:

let
Expand Down Expand Up @@ -111,6 +112,7 @@ stdenv.mkDerivation {
curl
gnupg
runtimeShell
applicationName
;
baseName = "thunderbird";
channel = "release";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ let
version,
sha512,
updateScript,
applicationName ? "Thunderbird",
}:
(buildMozillaMach rec {
pname = "thunderbird";
inherit version updateScript;
inherit version updateScript applicationName;
application = "comm/mail";
applicationName = "Mozilla Thunderbird";
binaryName = pname;
src = fetchurl {
url = "mirror://mozilla/thunderbird/releases/${version}/source/thunderbird-${version}.source.tar.xz";
Expand Down Expand Up @@ -98,6 +98,7 @@ rec {
thunderbird-esr = thunderbird-128;

thunderbird-128 = common {
applicationName = "Thunderbird ESR";
version = "128.6.0esr";
sha512 = "a561eac0bf0b8c72f3337ccebcde9099c342d1b31ce2b1f31096f1f805a195c49d627cf726cd56d41b21ec292d96fd577e8f226fcb24d8b13e0d773fc334b073";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ browser: args:
buildCommand =
old.buildCommand
+ ''
wrapProgram $out/bin/${browser.binaryName} \
wrapProgram "$executablePath" \
--prefix LD_LIBRARY_PATH ':' "${lib.makeLibraryPath [ gpgme ]}" \
--prefix PATH ':' "${lib.makeBinPath [ gnupg ]}"
'';
Expand Down
1 change: 1 addition & 0 deletions pkgs/by-name/vi/vimb-unwrapped/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ stdenv.mkDerivation rec {

passthru = {
inherit gtk3;
applicationName = "Vimb";
};

makeFlags = [ "PREFIX=${placeholder "out"}" ];
Expand Down
Loading

0 comments on commit fa0c455

Please sign in to comment.