Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firefox, thunderbird: enable wrapped derivations for darwin #377863

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -97,7 +98,7 @@ stdenv.mkDerivation {
'';

passthru = {
inherit binaryName;
inherit applicationName binaryName;
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 @@ -593,11 +596,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 @@ -622,14 +623,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 @@ -11,7 +11,7 @@ buildMozillaMach rec {
pname = "firefox-beta";
binaryName = pname;
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 @@ -11,7 +11,7 @@ buildMozillaMach rec {
pname = "firefox-devedition";
binaryName = pname;
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.7.0esr";
applicationName = "Firefox ESR";
src = fetchurl {
url = "mirror://mozilla/firefox/releases/${version}/source/firefox-${version}.source.tar.xz";
sha512 = "26f9661b395b85a44b42bd72ef1ad976c614216c68f6c2dd834d0ac8b84b9c9f398b8ac550a47396995d96e6bb5fa9a50064d7f2f526bddd45aed5039ef131b8";
Expand Down
80 changes: 56 additions & 24 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, lndir, config
{ stdenv, lib, makeDesktopItem, makeBinaryWrapper, lndir, config
, buildPackages
, jq, xdg-utils, writeText

Expand All @@ -23,12 +23,11 @@
browser:

let
isDarwin = stdenv.hostPlatform.isDarwin;
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.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 @@ -82,7 +81,8 @@ let
++ gtk_modules;
gtk_modules = [ libcanberra-gtk3 ];

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

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

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

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

buildCommand = ''
if [ ! -x "${browser}/bin/${applicationName}" ]
buildCommand = let
appPath = "Applications/${browser.applicationName}.app";
executablePrefix = if isDarwin then "${appPath}/Contents/MacOS" else "bin";
executablePath="${executablePrefix}/${applicationName}";
finalBinaryPath = "${executablePath}" + lib.optionalString (!isDarwin) "${nameSuffix}";
sourceBinary="${browser}/${executablePath}";
libDir = if isDarwin then "${appPath}/Contents/Resources" else "lib/${libName}";
prefsDir = if isDarwin then "${libDir}/browser/defaults/preferences" else "${libDir}/defaults/pref";
in ''
if [ ! -x "${sourceBinary}" ]
then
echo "cannot find executable file \`${browser}/bin/${applicationName}'"
echo "cannot find executable file \`${sourceBinary}'"
exit 1
fi

Expand Down Expand Up @@ -314,10 +322,31 @@ let

cd "$out"

'' + lib.optionalString isDarwin ''
cd "${appPath}"

# These files have to be copied and not symlinked, otherwise tabs crash.
# Maybe related to how omni.ja file is mmapped into memory. See:
# https://github.com/mozilla/gecko-dev/blob/b1662b447f306e6554647914090d4b73ac8e1664/modules/libjar/nsZipArchive.cpp#L204
for file in $(find . -type l -name "omni.ja"); do
rm "$file"
cp "${browser}/${appPath}/$file" "$file"
done

# Copy any embedded .app directories; plugin-container fails to start otherwise.
for dir in $(find . -type d -name '*.app'); do
rm -r "$dir"
cp -r "${browser}/${appPath}/$dir" "$dir"
done

cd ..

'' + ''

# create the wrapper

executablePrefix="$out/bin"
executablePath="$executablePrefix/${applicationName}"
executablePrefix="$out/${executablePrefix}"
executablePath="$out/${executablePath}"
oldWrapperArgs=()

if [[ -L $executablePath ]]; then
Expand Down Expand Up @@ -348,13 +377,15 @@ let

appendToVar makeWrapperArgs --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
concatTo makeWrapperArgs oldWrapperArgs
makeWrapper "$oldExe" "''${executablePath}${nameSuffix}" "''${makeWrapperArgs[@]}"

makeWrapper "$oldExe" "$out/${finalBinaryPath}" "''${makeWrapperArgs[@]}"

#############################
# #
# END EXTRA PREF CHANGES #
# #
#############################

'' + lib.optionalString (!isDarwin) ''
if [ -e "${browser}/share/icons" ]; then
mkdir -p "$out/share"
ln -s "${browser}/share/icons" "$out/share/icons"
Expand Down Expand Up @@ -389,12 +420,12 @@ let
# #
#########################
# user customization
mkdir -p $out/lib/${libName}
libDir="$out/${libDir}"

# creating policies.json
mkdir -p "$out/lib/${libName}/distribution"
mkdir -p "$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 @@ -405,25 +436,26 @@ let
done

# preparing for autoconfig
mkdir -p "$out/lib/${libName}/defaults/pref"
prefsDir="$out/${prefsDir}"
mkdir -p "$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
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 @@ -120,6 +121,7 @@ stdenv.mkDerivation {
};

passthru = {
inherit applicationName;
binaryName = "thunderbird";
gssSupport = true;
gtk3 = gtk3;
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,8 @@ rec {
thunderbird-esr = thunderbird-128;

thunderbird-128 = common {
applicationName = "Thunderbird ESR";

version = "128.7.1esr";
sha512 = "3f84e1f1a83379da1f154b66dbb5f941d04548ad017aab32aa9520f4315edb524e3754ac1fe9a7ae27f7aa33e2881c6783f11ccc53cda713f107760b7d880667";

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
2 changes: 1 addition & 1 deletion pkgs/by-name/fi/firefoxpwa/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ rustPlatform.buildRustPackage rec {
homepage = "https://pwasforfirefox.filips.si/";
changelog = "https://github.com/filips123/PWAsForFirefox/releases/tag/v${version}";
license = lib.licenses.mpl20;
platforms = lib.platforms.unix;
platforms = lib.platforms.linux;
maintainers = with lib.maintainers; [
camillemndn
pasqui23
Expand Down
3 changes: 3 additions & 0 deletions pkgs/by-name/mi/midori-unwrapped/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ stdenv.mkDerivation rec {

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

meta = with lib; {
Expand All @@ -65,5 +66,7 @@ stdenv.mkDerivation rec {
raskin
ramkromberg
];
# https://github.com/NixOS/nixpkgs/issues/374354
broken = true;
};
}
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