Firefox: Difference between revisions

From NixOS Wiki
Unabomberlive (talk | contribs)
No edit summary
Dander (talk | contribs)
capitalize firefox; don't use "you"; tidy up
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<translate>
<translate>
[https://www.mozilla.org/firefox Firefox] is a graphical web browser developed by Mozilla. It can be used with a [[Firefox Sync Server]].
<!--T:1-->
[https://www.mozilla.org/firefox Firefox] is a graphical web browser developed by Mozilla.
</translate>
</translate>
<translate>
<translate>
== Installation ==
== Installation == <!--T:2-->
</translate>
</translate>
<translate>
<translate>
<!--T:3-->
Set <code>programs.firefox.enable</code> to true in your system or [[Home Manager]] configuration.
Set <code>programs.firefox.enable</code> 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.
Keep in mind that the NixOS and Home Manager modules have different options, so choose accordingly.
</translate>
</translate>
<translate>
<translate>
== Firefox Variants ==
== Firefox Variants == <!--T:4-->
</translate>
</translate>
<translate>
<translate>
<!--T:5-->
There are several Firefox variants that you can choose 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.
</translate>
</translate>
<translate>
<translate>
<!--T:6-->
'''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.
</translate>
</translate>
<translate>
<translate>
=== Variant: Official Binaries ===
=== Variant: Official Binaries === <!--T:7-->
</translate>
</translate>
<translate>
<translate>
<!--T:8-->
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.
</translate>
</translate>
<translate>
<translate>
=== Variant: ESR ===
=== Variant: Extended Support Release (ESR) === <!--T:9-->
</translate>
</translate>
<translate>
<translate>
<code>firefox-esr</code> is the '''E'''xtended '''S'''upport '''R'''elease of Firefox provided by Mozilla, which receives only security updates and a more relaxed cadence of feature implementation.
<!--T:10-->
<code>firefox-esr</code> is a variant of Firefox provided by Mozilla, which receives security updates for a longer period of time and a more relaxed cadence of feature implementation. It also allows users to change otherwise untouchable behavior with Firefox using policies.
</translate>
</translate>
<translate>
<translate>
=== Variant: Nightly ===
=== Variant: Nightly === <!--T:11-->
</translate>
</translate>
<translate>
<translate>
<!--T:12-->
Nightly builds are daily builds of Firefox from the central Mozilla repository.
Nightly builds are daily builds of Firefox from the central Mozilla repository.
</translate>
</translate>
<translate>
<translate>
==== Reproducible ====
==== Method #1: Using nix-community/flake-firefox-nightly ==== <!--T:13-->
</translate>
</translate>
<translate>
<translate>
This method uses flakes to pull in nightly versions of Firefox in a reproducible way, and is recommended for use. If you don't want to use flakes, check out the next section.
<!--T:14-->
This method is reproducible but may lag behind the upstream version of Firefox Nightly. It uses flakes.  


<!--T:15-->
First, add the following inputs to your flake:
First, add the following inputs to your flake:
</translate>
</translate>
Line 51: Line 60:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--T:16-->
Then, using the [[Flakes#Using_nix_flakes_with_NixOS|specialArgs]] attribute to pass flake inputs to external configuration files, add the nightly package to your system:
Then, using the [[Flakes#Using_nix_flakes_with_NixOS|specialArgs]] attribute to pass flake inputs to external configuration files, add the nightly package to your system:
</translate>
</translate>
Line 61: Line 71:
}
}
</syntaxhighlight>
</syntaxhighlight>
==== Method #2: Using mozilla/nixpkgs-mozilla ==== <!--T:18-->
<nowiki></translate></nowiki>
<translate>
<translate>
The downside of using this method is that you'll have to update the flake input before you can get a new nightly version, which also means that you might miss new builds since the flake lags behind the nightly release.
<!--T:19-->
</translate>
This method is not necessarily reproducible without a [[Flake]]-like system because it fetches resources from non-pinned URLs, but it will always be the latest Nightly  version.
<translate>
==== Non-reproducible (Impure) ====
Using this method is bad for reproducibility since it fetches resources from non-pinned URLs, but it also means you always get the latest nightly version when you build your system.
</translate>
<translate>
{{tip|1=If you don't want to use flakes but you still want to reproducibly install Firefox nightly, you might want to use this method with [https://github.com/nmattia/niv niv].}}
</translate>
<translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
nixpkgs.overlays =
nixpkgs.overlays =
Line 86: Line 90:
</translate>
</translate>
<translate>
<translate>
Once you've added the overlay, you'll need to pass the <code>--impure</code> option to nix commands. For example, in order to build and activate your configuration, you'll have to run:
<!--T:22-->
It is also needed to pass the <code>--impure</code> option to nix commands. For example,
</translate>
</translate>
<syntaxHighlight lang="console">
<syntaxHighlight lang="console">
Line 92: Line 97:
</syntaxHighlight>
</syntaxHighlight>
<translate>
<translate>
== Customizing with [[Home Manager]] ==
== Customizing with [[Home Manager]] == <!--T:23-->
</translate>
</translate>
<translate>
<translate>
<!--T:24-->
Home manager allows more customization for firefox. Such as  extensions, search engines, bookmarks, [https://www.userchrome.org/ userChrome] and [https://kb.mozillazine.org/User.js_file user.js]. The example below shows a basic config defining Nix packages & options as a search engine.
Home manager allows more customization for firefox. Such as  extensions, search engines, bookmarks, [https://www.userchrome.org/ userChrome] and [https://kb.mozillazine.org/User.js_file user.js]. The example below shows a basic config defining Nix packages & options as a search engine.
</translate>
</translate>
<translate>
<translate>
<!--T:25-->
[https://nix-community.github.io/home-manager/options.xhtml More options are available on Home Manager's site]
[https://nix-community.github.io/home-manager/options.xhtml More options are available on Home Manager's site]
</translate>
</translate>
Line 135: Line 142:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
== FAQ ==
== FAQ == <!--T:26-->
</translate>
</translate>
<translate>
<translate>
=== How do I use ALSA with Firefox instead of PulseAudio? ===
=== How do I use ALSA with Firefox instead of PulseAudio? === <!--T:27-->
</translate>
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 144: Line 151:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
== Tips ==
== Tips == <!--T:28-->
</translate>
</translate>
<translate>
<translate>
<!--T:29-->
=== Enabling
=== Enabling
[https://community.kde.org/Plasma/Browser_Integration#How_to_install Plasma Browser Integration] ===
[https://community.kde.org/Plasma/Browser_Integration#How_to_install Plasma Browser Integration] ===
</translate>
</translate>
<translate>
<translate>
<!--T:30-->
1. Add the following line to your <code>configuration.nix</code> (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):
</translate>
</translate>
Line 158: Line 167:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--T:31-->
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].
</translate>
</translate>
<translate>
<translate>
=== Use KDE file picker ===
=== Use KDE file picker === <!--T:32-->
</translate>
</translate>
<translate>
<translate>
<!--T:33-->
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>
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>
</translate>
</translate>
Line 177: Line 188:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
=== Use xinput2 ===
=== Use xinput2 === <!--T:34-->
</translate>
</translate>
<translate>
<translate>
<!--T:35-->
You can make Firefox use xinput2 by setting the <code>MOZ_USE_XINPUT2</code> 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:  
You can make Firefox use xinput2 by setting the <code>MOZ_USE_XINPUT2</code> 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:  
</translate>
</translate>
Line 189: Line 201:
<translate>
<translate>
== Troubleshooting==
== Troubleshooting==
=== <code>nativeMessagingHosts</code> doesn't work === <!--T:40-->
</translate>
</translate>
<translate>
<translate>
=== If you can't start the browser because of a configuration error ===
<!--T:41-->
These options, for example  <code>enablePlasmaBrowserIntegration</code>,  or<code>enableGnomeExtensions</code>,  do not work with the <code>bin</code> variants of the Firefox packages or with Firefox installed via<code>nix-env</code>.
</translate>
<hr />


For example:  
<translate>
=== Screen Sharing under Wayland === <!--T:43-->
</translate>
</translate>
<syntaxhighlight lang="text">
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
</syntaxhighlight>
<translate>
<translate>
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.  
<!--T:44-->
When using Firefox with Wayland, screen sharing options might be limited and require additional configuration (exact capabilities vary with different compositors).
</translate>
</translate>
<translate>
<translate>
=== <code>nativeMessagingHosts</code> doesn't work ===
<!--T:47-->
* Enable [https://pipewire.org/ PipeWire]
</translate>
</translate>
<translate>
Such as <code>enablePlasmaBrowserIntegration</code>, <code>enableGnomeExtensions</code>, and <code>enableBrowserpass</code>.


They do not work with the <code>firefox-bin</code> derivation<ref>https://github.com/NixOS/nixpkgs/issues/47340#issuecomment-476368401</ref> or with <code>firefox</code> installed via <code>nix-env</code>
<syntaxhighlight lang="nix">
services.pipewire.enable = true;
</syntaxhighlight>


<hr />
<references />
</translate>
<translate>
<translate>
=== Screen Sharing under Wayland ===
<!--T:45-->
* Add PipeWire support to Firefox:
</translate>
</translate>
<translate>
<translate>
When using Firefox with Wayland, screen sharing options might be limited and require additional configuration (exact capabilities vary with different compositors).
<!--T:46-->
</translate>
<syntaxhighlight lang="nixos">
<translate>
programs.firefox.enable = true
* add Pipewire support to Firefox:
programs.firefox.wrapperConfig = {
</translate>
  pipewireSupport = true;
<translate>
};
<syntaxhighlight lang="nix">
</syntaxhighlight>
Alternatively, it is possible to override the Firefox derivation with [[PipeWire]] support to it:<syntaxhighlight lang="diff">
environment.systemPackages = [
environment.systemPackages = [
  # Replace this
pkgs.firefox
  pkgs.firefox
pkgs.wrapFirefox (pkgs.firefox-unwrapped.override { pipewireSupport = true;}) {})
  # With this
  (pkgs.wrapFirefox (pkgs.firefox-unwrapped.override { pipewireSupport = true;}) {})
];
];
</syntaxhighlight>
</syntaxhighlight>
</translate>
</translate>
<translate>
<translate>
* Enable [https://pipewire.org/ PipeWire]
<!--T:48-->
</translate>
<syntaxhighlight lang="nix">
services.pipewire.enable = true;
</syntaxhighlight>
<translate>
* Enable [https://github.com/flatpak/xdg-desktop-portal/blob/master/README.md xdg desktop integration]:
* Enable [https://github.com/flatpak/xdg-desktop-portal/blob/master/README.md xdg desktop integration]:
</translate>
</translate>
Line 256: Line 261:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--T:49-->
* Set environment variables to hint Firefox to use Wayland features. E.g.:
* Set environment variables to hint Firefox to use Wayland features. E.g.:
</translate>
</translate>
<translate>
<translate>
<!--T:50-->
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# Classical NixOS setup
# NixOS setup
environment.sessionVariables = {
environment.sessionVariables = {
   # only needed for Sway
   # only needed for Sway
   XDG_CURRENT_DESKTOP = "sway";  
   XDG_CURRENT_DESKTOP = "sway";  
};
};
 
</syntaxhighlight>
</translate>
<translate>
<!--T:51-->
<syntaxhighlight lang="nix">
# Home Manager setup
# Home Manager setup
home.sessionVariables = {
home.sessionVariables = {
Line 274: Line 285:
</translate>
</translate>
<translate>
<translate>
<!--T:52-->
* Ensure that the environment variables are correctly set for the user systemd units, e.g.
* Ensure that the environment variables are correctly set for the user systemd units, e.g.
</translate>
</translate>
<translate>
<translate>
<syntaxhighlight lang="bash">
<!--T:53-->
# Sway users might achieve this by adding the following to their Sway config file
# 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
# This ensures all user units started after the command (not those already running) set the variables
</translate>
<syntaxhighlight lang="bash">
exec systemctl --user import-environment
exec systemctl --user import-environment
</syntaxhighlight>
</syntaxhighlight>
</translate>


[[Category:Cookbook]]
[[Category:Cookbook]]
[[Category:Applications]]
[[Category:Applications]]
[[Category:Web Browser]]

Latest revision as of 23:48, 26 October 2024

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: Extended Support Release (ESR)

firefox-esr is a variant of Firefox provided by Mozilla, which receives security updates for a longer period of time and a more relaxed cadence of feature implementation. It also allows users to change otherwise untouchable behavior with Firefox using policies.

Variant: Nightly

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

Method #1: Using nix-community/flake-firefox-nightly

This method is reproducible but may lag behind the upstream version of Firefox Nightly. It uses flakes.

First, add the following inputs to your flake:

inputs = {
  firefox.url = "github:nix-community/flake-firefox-nightly";
  firefox.inputs.nixpkgs.follows = "nixpkgs";
};

Then, using the specialArgs attribute to pass flake inputs to external configuration files, add the nightly package to your system:

{ pkgs, inputs, config, ... }:
{
  environment.systemPackages = [
    inputs.firefox.packages.${pkgs.system}.firefox-nightly-bin
  ];
}

Method #2: Using mozilla/nixpkgs-mozilla

</translate> This method is not necessarily reproducible without a Flake-like system because it fetches resources from non-pinned URLs, but it will always be the latest Nightly version.

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;

It is also needed to pass the --impure option to nix commands. For example,

$ nixos-rebuild switch --impure

Customizing with Home Manager

Home manager allows more customization for firefox. Such as extensions, search engines, bookmarks, userChrome and user.js. The example below shows a basic config defining Nix packages & options as a search engine. More options are available on Home Manager's site

home-manager.users.username = {
  programs.firefox = {
    enable = true;
    profiles = {
      "user" = {
        id = 0;
        isDefault = true;

        search.engines = {
          "Nix Packages" = {
            urls = [{
              template = "https://search.nixos.org/packages";
              params = [
                { name = "query"; value = "{searchTerms}"; }
              ];
            }];
            icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
            definedAliases = [ "@np" ];
          };
          "Nix Options" = {
            definedAliases = [ "@no" ];
            urls = [{
              template = "https://search.nixos.org/options";
              params = [
                { name = "query"; value = "{searchTerms}"; }
              ];
            }];
          };
        };
      };
    };
  };

FAQ

How do I use ALSA with Firefox instead of PulseAudio?

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

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

nativeMessagingHosts doesn't work

These options, for example enablePlasmaBrowserIntegration, orenableGnomeExtensions, do not work with the bin variants of the Firefox packages or with Firefox installed vianix-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).

services.pipewire.enable = true;
  • Add PipeWire support to Firefox:
programs.firefox.enable = true
programs.firefox.wrapperConfig = {
  pipewireSupport = true;
};

Alternatively, it is possible to override the Firefox derivation with PipeWire support to it:

environment.systemPackages = [
-  pkgs.firefox
+  pkgs.wrapFirefox (pkgs.firefox-unwrapped.override { pipewireSupport = true;}) {})
];
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.:
# 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.
  1. Sway users might achieve this by adding the following to their Sway config file
  2. This ensures all user units started after the command (not those already running) set the variables
exec systemctl --user import-environment