Firefox: Difference between revisions

From NixOS Wiki
imported>Writer
Remove reduncancy and use "variant" throughout and in title to make separation clearer and easier to navigate
imported>SuperSamus
No edit summary
Line 8: Line 8:
== Firefox Variants ==
== Firefox Variants ==


There are several Firefox variants that you can chose to install. To choose a variant, set <code>programs.firefox.package</code> accordingly.
There are several Firefox variants that you can choose to install. To choose a variant, set <code>programs.firefox.package</code> accordingly.


'''Note:''' The packages for the variants listed below are installed ''instead'' of the normal <code>firefox</code> package. Thus, you'll have to choose one among these options.
'''Note:''' The packages for the variants listed below are installed ''instead'' of the normal <code>firefox</code> package. Thus, you'll have to choose one among these options.


=== Variant: Official Binaries ===
=== Variant: Official Binaries ===
Mozilla provides official pre-built Firefox binaries. This is the <code>firefox-bin</code> package and will be downloaded directly from the Mozilla servers.
Mozilla provides official pre-built Firefox binaries. This is the <code>firefox-bin</code> package and will be downloaded directly from the Mozilla servers.
=== Variant: Wayland ===
Users running a Wayland compositor (such as [[Sway]]) may want to use a Wayland-compatible variant of Firefox (<code>firefox-wayland</code>).  This can help with a number of issues such as phantom scrolling.
==== Screen Sharing ====
When using Firefox with Wayland, screen sharing options might be limited and require additional configuration (exact capabilities vary with different compositors).
* Use <code>firefox-wayland</code>
* Enable [https://pipewire.org/ PipeWire]:<syntaxhighlight lang="nix">
services.pipewire.enable = true;
</syntaxhighlight>
* Enable [https://github.com/flatpak/xdg-desktop-portal/blob/master/README.md xdg desktop integration]:<syntaxhighlight lang="nix">
xdg = {
  portal = {
    enable = true;
    extraPortals = with pkgs; [
      xdg-desktop-portal-wlr
      xdg-desktop-portal-gtk
    ];
  };
};
</syntaxhighlight>
* Set environment variables to hint Firefox to use Wayland features. E.g.:<syntaxhighlight lang="nix">
# Classical NixOS setup
environment.sessionVariables = {
  MOZ_ENABLE_WAYLAND = 1;
  # only needed for Sway
  XDG_CURRENT_DESKTOP = "sway";
};
# Home Manager setup
home.sessionVariables = {
  MOZ_ENABLE_WAYLAND = 1;
  # only needed for Sway
  XDG_CURRENT_DESKTOP = "sway";
};
</syntaxhighlight>
* Ensure that the environment variables are correctly set for the user systemd units, e.g.:
<syntaxhighlight lang="bash">
# Sway users might achieve this by adding the following to their Sway config file
# This ensures all user units started after the command (not those already running) set the variables
exec systemctl --user import-environment
</syntaxhighlight>


=== Variant: ESR ===
=== Variant: ESR ===
Line 98: Line 52:


=== Enabling [https://community.kde.org/Plasma/Browser_Integration#How_to_install Plasma Browser Integration]  ===
=== Enabling [https://community.kde.org/Plasma/Browser_Integration#How_to_install Plasma Browser Integration]  ===
1. Add the following line to your configuration.nix (note that [[KDE#Installation|enabling Plasma]] automatically does this):
1. Add the following line to your <code>configuration.nix</code> (note that [[KDE#Installation|enabling Plasma]] automatically does this):


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
nixpkgs.config.firefox.enablePlasmaBrowserIntegration = true;
programs.firefox.nativeMessagingHosts.packages = [ pkgs.plasma5Packages.plasma-browser-integration ];
</syntaxhighlight>
</syntaxhighlight>
If you're wondering where this part is coming from see [https://nixos.org/nixos/manual/#sec-customising-packages NixOS Manual:Customising Packages]


2. Install [https://addons.mozilla.org/en-US/firefox/addon/plasma-integration/ KDE's Firefox extension].
2. Install [https://addons.mozilla.org/en-US/firefox/addon/plasma-integration/ KDE's Firefox extension].
Line 110: Line 62:
=== Use KDE file picker ===
=== Use KDE file picker ===


You must instruct Firefox to use the file picker offered by the XDG Desktop Portal framework. This setting can be found in Firefox's ''about:config'' as ''widget.use-xdg-desktop-portal.file-picker''. The value 1 means "always". To set it using NixOS, add to ''configuration.nix''
You must instruct Firefox to use the file picker offered by the XDG Desktop Portal framework. This setting can be found in Firefox's ''about:config'' as ''widget.use-xdg-desktop-portal.file-picker''. The value 1 means "always". To set it using NixOS, add to '<code>configuration.nix'</code>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 118: Line 70:
     enable = true;
     enable = true;
     preferences = {
     preferences = {
    "widget.use-xdg-desktop-portal.file-picker" = 1;
      "widget.use-xdg-desktop-portal.file-picker" = 1;
     };
     };
   };
   };
Line 141: Line 93:
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
firefox
firefox
1554035168269 Marionette FATAL Error de análisis XML: entidad indefinida
1554035168269 Marionette FATAL XML parsing error: undefined entity
Ubicación: chrome://browser/content/browser.xul
Location: chrome://browser/content/browser.xul
Línea 2526, columna 13:            <toolbarbutton id="tracking-protection-preferences-button"
Line 2526, column 13:            <toolbarbutton id="tracking-protection-preferences-button"
JavaScript error: resource:///modules/aboutpages/AboutPrivateBrowsingHandler.jsm, line 28: TypeError: this.pageListener is undefined
JavaScript error: resource:///modules/aboutpages/AboutPrivateBrowsingHandler.jsm, line 28: TypeError: this.pageListener is undefined
</syntaxhighlight>
</syntaxhighlight>
Line 149: Line 101:
An easy way to get away from this is to start firefox with the <code>firefox -safe-mode</code> command. Then you can troubleshoot your actual problem or you can call your luck by calling the refresh option (a special button will appear when firefox starts in this mode). This will reset your configuration to a sane state and you will be usually able to start the browser again, but you will lose most of your customization.  
An easy way to get away from this is to start firefox with the <code>firefox -safe-mode</code> command. Then you can troubleshoot your actual problem or you can call your luck by calling the refresh option (a special button will appear when firefox starts in this mode). This will reset your configuration to a sane state and you will be usually able to start the browser again, but you will lose most of your customization.  


=== <code>nativeMessagingHosts</code> don't work ===
=== <code>nativeMessagingHosts</code> doesn't work ===


such as <code>enablePlasmaBrowserIntegration</code>, <code>enableGnomeExtensions</code>, and <code>enableBrowserpass</code>.
such as <code>enablePlasmaBrowserIntegration</code>, <code>enableGnomeExtensions</code>, and <code>enableBrowserpass</code>.
Line 157: Line 109:
<hr />
<hr />
<references />
<references />
=== Screen Sharing under Wayland ===
When using Firefox with Wayland, screen sharing options might be limited and require additional configuration (exact capabilities vary with different compositors).
* Use <code>firefox-wayland</code>
* Enable [https://pipewire.org/ PipeWire]:<syntaxhighlight lang="nix">
services.pipewire.enable = true;
</syntaxhighlight>
* Enable [https://github.com/flatpak/xdg-desktop-portal/blob/master/README.md xdg desktop integration]:<syntaxhighlight lang="nix">
xdg = {
  portal = {
    enable = true;
    extraPortals = with pkgs; [
      xdg-desktop-portal-wlr
      xdg-desktop-portal-gtk
    ];
  };
};
</syntaxhighlight>
* Set environment variables to hint Firefox to use Wayland features. E.g.:<syntaxhighlight lang="nix">
# Classical NixOS setup
environment.sessionVariables = {
  # only needed for Sway
  XDG_CURRENT_DESKTOP = "sway";
};
# Home Manager setup
home.sessionVariables = {
  # only needed for Sway
  XDG_CURRENT_DESKTOP = "sway";
};
</syntaxhighlight>
* Ensure that the environment variables are correctly set for the user systemd units, e.g.:
<syntaxhighlight lang="bash">
# Sway users might achieve this by adding the following to their Sway config file
# This ensures all user units started after the command (not those already running) set the variables
exec systemctl --user import-environment
</syntaxhighlight>


[[Category:Configuration]]
[[Category:Configuration]]
[[Category:Applications]]
[[Category:Applications]]

Revision as of 09:47, 27 October 2023

Firefox is a graphical web browser developed by Mozilla.

Installation

Set programs.firefox.enable to true in your system or Home Manager configuration. Keep in mind that the NixOS and Home Manager modules have different options, so choose accordingly.

Firefox Variants

There are several Firefox variants that you can choose to install. To choose a variant, set programs.firefox.package accordingly.

Note: The packages for the variants listed below are installed instead of the normal firefox package. Thus, you'll have to choose one among these options.

Variant: Official Binaries

Mozilla provides official pre-built Firefox binaries. This is the firefox-bin package and will be downloaded directly from the Mozilla servers.

Variant: ESR

firefox-esr is the Extended Support Release of Firefox provided by Mozilla, which receives only security updates and a more relaxed cadence of feature implementation.

Variant: Nightly

Nightly builds are daily builds of Firefox from the central Mozilla repository.

To use them

nixpkgs.overlays =
  let
    # Change this to a rev sha to pin
    moz-rev = "master";
    moz-url = builtins.fetchTarball { url = "https://github.com/mozilla/nixpkgs-mozilla/archive/${moz-rev}.tar.gz";};
    nightlyOverlay = (import "${moz-url}/firefox-overlay.nix");
  in [
    nightlyOverlay
  ];
programs.firefox.package = pkgs.latest.firefox-nightly-bin;

FAQ

How do I use ALSA with Firefox instead of PulseAudio?

programs.firefox.package = (pkgs.wrapFirefox.override { libpulseaudio = pkgs.libpressureaudio; }) pkgs.firefox-unwrapped { };

I want Firefox, what is Nightly?

Mozilla's trademarks on Firefox disallows distributing unofficial builds using the Firefox trademark. This is why the Nix-built Firefox is named Nightly.

The official builds are available by enabling unfree and installing firefox-bin.

Tips

Enabling Plasma Browser Integration

1. Add the following line to your configuration.nix (note that enabling Plasma automatically does this):

programs.firefox.nativeMessagingHosts.packages = [ pkgs.plasma5Packages.plasma-browser-integration ];

2. Install KDE's Firefox extension.

Use KDE file picker

You must instruct Firefox to use the file picker offered by the XDG Desktop Portal framework. This setting can be found in Firefox's about:config as widget.use-xdg-desktop-portal.file-picker. The value 1 means "always". To set it using NixOS, add to 'configuration.nix'

  # Make Firefox use the KDE file picker.
  # Preferences source: https://wiki.archlinux.org/title/firefox#KDE_integration
  programs.firefox = {
    enable = true;
    preferences = {
      "widget.use-xdg-desktop-portal.file-picker" = 1;
    };
  };

Use xinput2

You can make Firefox use xinput2 by setting the MOZ_USE_XINPUT2 environment variable. This improves touchscreen support and enables additional touchpad gestures. It also enables smooth scrolling as opposed to the stepped scrolling that Firefox has by default. To do this, put the following in your config:

environment.sessionVariables = {
  MOZ_USE_XINPUT2 = "1";
};

Troubleshooting

If you can't start the browser because of a configuration error

For example:

firefox
1554035168269	Marionette	FATAL	XML parsing error: undefined entity
Location: chrome://browser/content/browser.xul
Line 2526, column 13:            <toolbarbutton id="tracking-protection-preferences-button"
JavaScript error: resource:///modules/aboutpages/AboutPrivateBrowsingHandler.jsm, line 28: TypeError: this.pageListener is undefined

An easy way to get away from this is to start firefox with the firefox -safe-mode command. Then you can troubleshoot your actual problem or you can call your luck by calling the refresh option (a special button will appear when firefox starts in this mode). This will reset your configuration to a sane state and you will be usually able to start the browser again, but you will lose most of your customization.

nativeMessagingHosts doesn't work

such as enablePlasmaBrowserIntegration, enableGnomeExtensions, and enableBrowserpass.

They do not work with the firefox-bin derivation[1] or with firefox installed via nix-env


Screen Sharing under Wayland

When using Firefox with Wayland, screen sharing options might be limited and require additional configuration (exact capabilities vary with different compositors).

  • Use firefox-wayland
  • Enable PipeWire:
    services.pipewire.enable = true;
    
  • Enable xdg desktop integration:
    xdg = {
      portal = {
        enable = true;
        extraPortals = with pkgs; [
          xdg-desktop-portal-wlr
          xdg-desktop-portal-gtk
        ];
      };
    };
    
  • Set environment variables to hint Firefox to use Wayland features. E.g.:
    # Classical NixOS setup
    environment.sessionVariables = {
      # only needed for Sway
      XDG_CURRENT_DESKTOP = "sway"; 
    };
    
    # Home Manager setup
    home.sessionVariables = {
      # only needed for Sway
      XDG_CURRENT_DESKTOP = "sway"; 
    };
    
  • Ensure that the environment variables are correctly set for the user systemd units, e.g.:
# Sway users might achieve this by adding the following to their Sway config file
# This ensures all user units started after the command (not those already running) set the variables
exec systemctl --user import-environment