Jump to content

Firefox/zh: Difference between revisions

From Official NixOS Wiki
Ardenet (talk | contribs)
Created page with "== 使用技巧 =="
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
Created page with "== 参考 =="
 
(8 intermediate revisions by the same user not shown)
Line 315: Line 315:
== 使用技巧 ==
== 使用技巧 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Force_XWayland_(X11)_instead_of_Wayland"></span>
==== Force XWayland (X11) instead of Wayland ====
==== 强制使用 XWayland (X11) 而非 Wayland ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 329: Line 328:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Touchpad_Gestures_and_Smooth_Scrolling"></span>
==== Touchpad Gestures and Smooth Scrolling ====
==== 触控板手势和流畅滚动 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 341: Line 339:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="KDE_Plasma_Integration"></span>
==== KDE Plasma Integration ====
==== KDE Plasma 集成 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 355: Line 352:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Use_KDE_file_picker"></span>
==== Use KDE file picker ====
==== 使用 KDE 文件选择器 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 369: Line 365:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Troubleshooting"></span>
== Troubleshooting ==
== 故障排除 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Native_Messaging_Hosts_Fail_to_Load"></span>
==== Native Messaging Hosts Fail to Load ====
==== 本地消息传递进程加载失败 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 381: Line 375:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="ALSA_audio_instead_of_PulseAudio"></span>
==== ALSA audio instead of PulseAudio ====
==== 使用 ALSA 音频而非 PulseAudio ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 391: Line 384:
{{code|lang=nix|line=no|1=programs.firefox.package = pkgs.wrapFirefox pkgs.firefox-unwrapped { libpulseaudio = pkgs.libalsa; };}}
{{code|lang=nix|line=no|1=programs.firefox.package = pkgs.wrapFirefox pkgs.firefox-unwrapped { libpulseaudio = pkgs.libalsa; };}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Screen_Sharing_under_Wayland"></span>
==== Screen Sharing under Wayland ====
==== Wayland 下的屏幕共享 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 412: Line 404:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="See_also"></span>
== See also ==
== 另见 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 422: Line 413:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="References"></span>
== References ==
== 参考 ==
</div>


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

Latest revision as of 19:45, 7 March 2026

Mozilla Firefox

Web Browser Application

100%
Developer(s)Mozilla Foundation & Community
Latest releaseFirefox 140.0 (June 24, 2025)
StatusActive
Operating SystemCross-platform (Linux, macOS, Windows, *BSD)
LicenseMozilla Public License 2.0
External links
Websitemozilla.org/firefox
GitHubmozilla/firefox
Bug trackerBugzilla
DocumentationOfficial Support

Firefox[1] is a free and open-source web browser developed by the Mozilla Foundation. It is known for its focus on privacy, security, and user freedom, offering a customizable experience through a rich ecosystem of add-ons and themes.

安装

Shell

$ nix-shell -p firefox

The command above makes firefox available in your current shell without modifying any configuration files.

系统设置

# Example for /etc/nixos/configuration.nix
environment.systemPackages = [
  pkgs.firefox
];

# User-specific installation (in ~/.config/nixpkgs/home.nix)
home.packages = [
  pkgs.firefox
];

After rebuilding with nixos-rebuild switch, Firefox will be installed system-wide.

配置

基础

programs.firefox = {
  enable = true;

  languagePacks = [ "en-US" "de" "fr" ];

  preferences = {
    "browser.startup.homepage"      = "https://example.com";
    "privacy.resistFingerprinting"  = true;
  };

  policies = {
    DisableTelemetry = true;
  };
};

The snippet above enables Firefox for all users (or the current Home Manager profile, if placed in home.nix).

进阶

Home Manager allows for deep customization of Firefox, including extensions, search engines, bookmarks, and themes. The example below shows a configuration for adding custom search engines with aliases.

programs.firefox = {
  enable = true;

  languagePacks = [ "en-US" ];

  policies = {
    # Updates & Background Services
    AppAutoUpdate                 = false;
    BackgroundAppUpdate           = false;

    # Feature Disabling
    DisableBuiltinPDFViewer       = true;
    DisableFirefoxStudies         = true;
    DisableFirefoxAccounts        = true;
    DisableFirefoxScreenshots     = true;
    DisableForgetButton           = true;
    DisableMasterPasswordCreation = true;
    DisableProfileImport          = true;
    DisableProfileRefresh         = true;
    DisableSetDesktopBackground   = true;
    DisablePocket                 = true;
    DisableTelemetry              = true;
    DisableFormHistory            = true;
    DisablePasswordReveal         = true;

    # Access Restrictions
    BlockAboutConfig              = false;
    BlockAboutProfiles            = true;
    BlockAboutSupport             = true;

    # UI and Behavior
    DisplayMenuBar                = "never";
    DontCheckDefaultBrowser       = true;
    HardwareAcceleration          = false;
    OfferToSaveLogins             = false;
    DefaultDownloadDirectory      = "${home}/Downloads";

    # Extensions
    ExtensionSettings = let
      moz = short: "https://addons.mozilla.org/firefox/downloads/latest/${short}/latest.xpi";
    in {
      "*".installation_mode = "blocked";

      "uBlock0@raymondhill.net" = {
        install_url       = moz "ublock-origin";
        installation_mode = "force_installed";
        updates_disabled  = true;
      };

      "{f3b4b962-34b4-4935-9eee-45b0bce58279}" = {
        install_url       = moz "animated-purple-moon-lake";
        installation_mode = "force_installed";
        updates_disabled  = true;
      };

      "{73a6fe31-595d-460b-a920-fcc0f8843232}" = {
        install_url       = moz "noscript";
        installation_mode = "force_installed";
        updates_disabled  = true;
      };
    };

    # Extension configuration 
    "3rdparty".Extensions = {
      "uBlock0@raymondhill.net".adminSettings = {
        userSettings = rec {
          uiTheme            = "dark";
          uiAccentCustom     = true;
          uiAccentCustom0    = "#8300ff";
          cloudStorageEnabled = mkForce false;

          importedLists = [
            "https:#filters.adtidy.org/extension/ublock/filters/3.txt"
            "https:#github.com/DandelionSprout/adfilt/raw/master/LegitimateURLShortener.txt"
          ];

          externalLists = lib.concatStringsSep "\n" importedLists;
        };

        selectedFilterLists = [
          "CZE-0"
          "adguard-generic"
          "adguard-annoyance"
          "adguard-social"
          "adguard-spyware-url"
          "easylist"
          "easyprivacy"
          "https:#github.com/DandelionSprout/adfilt/raw/master/LegitimateURLShortener.txt"
          "plowe-0"
          "ublock-abuse"
          "ublock-badware"
          "ublock-filters"
          "ublock-privacy"
          "ublock-quick-fixes"
          "ublock-unbreak"
          "urlhaus-1"
        ];
      };
    };
  };

  profiles.default.search = {
    force           = true;
    default         = "DuckDuckGo";
    privateDefault  = "DuckDuckGo";

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

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

      "NixOS Wiki" = {
        urls = [
          {
            template = "https://wiki.nixos.org/w/index.php";
            params = [
              { name = "search"; value = "{searchTerms}"; }
            ];
          }
        ];
        icon           = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
        definedAliases = [ "@nw" ];
      };
    };
  };
};

Firefox 版本

There are several Firefox variants available. To choose one, set the programs.firefox.package option accordingly.

Note: {{{1}}}

版本:官方二进制程序

Mozilla provides official pre-built Firefox binaries via the firefox-bin package, which are downloaded directly from Mozilla's servers.

版本:扩展支持版本 (ESR)

firefox-esr is a variant that receives security updates for a longer period with a slower feature implementation cadence. It also allows for more extensive policy-based configuration.

版本:夜间版

Nightly builds are daily builds from the central Mozilla repository.

方法一:使用 nix-community/flake-firefox-nightly

This method is reproducible but may lag behind the upstream version. First, add the input to your flake:

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

Then, add the package to your system:

# In configuration.nix, assuming use of specialArgs
environment.systemPackages = [
  inputs.firefox.packages.${pkgs.stdenv.hostPlatform.system}.firefox-nightly-bin
];

方法二:使用 mozilla/nixpkgs-mozilla

This method is not necessarily reproducible without a flake-like system but will always be the latest version.

nixpkgs.overlays = [
  (import (builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz"))
];
programs.firefox.package = pkgs.latest.firefox-nightly-bin;

Using this method requires the --impure flag for Nix commands, for example:

$ nixos-rebuild switch --impure

使用技巧

强制使用 XWayland (X11) 而非 Wayland

Firefox defaults to native Wayland when running under a Wayland compositor. To force it to use XWayland (X11) instead:

environment.sessionVariables.MOZ_ENABLE_WAYLAND = "0";

This is useful when troubleshooting Wayland-specific issues or when certain features work better under X11.

触控板手势和流畅滚动

Enable xinput2 to improve touchscreen support and enable additional touchpad gestures and smooth scrolling.

environment.sessionVariables.MOZ_USE_XINPUT2 = "1";

KDE Plasma 集成

1. Add the native messaging host package to your configuration:

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

2. Install the corresponding browser add-on.

使用 KDE 文件选择器

To use the KDE file picker instead of the GTK one, set the following preference:

programs.firefox.preferences = {
  "widget.use-xdg-desktop-portal.file-picker" = 1;
};

故障排除

本地消息传递进程加载失败

Native messaging hosts (used for extensions like Plasma Integration) do not work with the -bin variants of Firefox or with Firefox installed imperatively via nix-env. You must use a variant built from source via your NixOS or Home Manager configuration.

使用 ALSA 音频而非 PulseAudio

To force Firefox to use ALSA, you can override it with a wrapper:

programs.firefox.package = pkgs.wrapFirefox pkgs.firefox-unwrapped { libpulseaudio = pkgs.libalsa; };

Wayland 下的屏幕共享

Screen sharing on Wayland requires enabling PipeWire and the appropriate XDG Desktop Portals.

services.pipewire.enable = true;
xdg.portal = {
  enable = true;
  # Add the portal for your compositor, e.g.:
  extraPortals = with pkgs; [
    xdg-desktop-portal-wlr # For Sway/wlroots
    # xdg-desktop-portal-gtk # For GNOME
    # xdg-desktop-portal-kde # For KDE
  ];
};

另见

参考

  1. Mozilla Foundation, "Firefox", Official Website, Accessed June 2025. https://www.mozilla.org/firefox