Jump to content

Chromium/zh: Difference between revisions

From Official NixOS Wiki
Ardenet (talk | contribs)
Created page with "在某些情况下,$chrome_gpu_link 将显示“视频解码(Video Decode)”已启用,但“视频加速信息(Video Acceleration Information)”为空,此时 $chrome_media_link 使用的是 FFmpeg 视频解码器(软件解码)。如果出现这种情况,请尝试启用以下功能:"
Ardenet (talk | contribs)
Created page with "== 启用 DRM(Widevine 支持)=="
Tags: Mobile edit Mobile web edit
Line 120: Line 120:
</nowiki>}}
</nowiki>}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Enabling_native_Wayland_support"></span>
== Enabling native Wayland support ==
== 启用原生 Wayland 支持 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
您可以通过将 `NIXOS_OZONE_WL` 环境变量设置为 `1`,在所有基于 Chromium 的应用程序和大多数 Electron 应用程序中启用原生 Wayland 支持。
You can enable native Wayland support in all Chromium based and most Electron apps by setting the `NIXOS_OZONE_WL` environment variable to `1`.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Enabling_DRM_(Widevine_support)"></span>
== Enabling DRM (Widevine support) ==
== 启用 DRM(Widevine 支持)==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Revision as of 15:52, 31 May 2026

安裝

NixOS

添加 chromiumsystemPackages

更新瀏覽器政策

In Chromium, policy settings are accessible via chrome://policy. They allow the user to change enterprise policies affecting things like

  • Creating webapps when the browser is installed
  • Finding and downloading browser extensions automatically
  • Enabling or disabling the dinosaur game when the device is offline
  • Disable screenshots to be taken with browser extensions
  • Block all downloads from the browser (if you want to do that for some reason)
  • and more!

A full list of policies can be found at Chrome Enterprise Policy List & Management.

原生支持的政策

By default NixOS provides a few policies that can be enabled directly, a simple example is given below to understand how these are implemented

  programs.chromium = {
    enable = true;
    homepageLocation = "https://www.startpage.com/";
    extensions = [
      "eimadpbcbfnmbkopoojfekhnkhdbieeh;https://clients2.google.com/service/update2/crx" # dark reader
      "aapbdbdomjkkjkaonfhkkikfgjllcleb;https://clients2.google.com/service/update2/crx" # google translate
    ];
    extraOpts = {
      "WebAppInstallForceList" = [
        {
          "custom_name" = "Youtube";
          "create_desktop_shortcut" = false;
          "default_launch_container" = "window";
          "url" = "https://youtube.com";
        }
      ];
    };
  };
  • homepageLocation option allows you to set the site that the homepage will open on
  • extensions allows for the download of extensions directly in the browser through a simple list of the extension ID's that can be obtained from the Chrome Web Store by opening an extension page and copying the last part of the URL
    • In the example however there is another component, the download source from which the extensions will be downloaded
    • The URL provided in the list is the link that is used by google for managing, checking and updating extensions
    • So the method of just placing the extension ID can work like this: "fnpbehpgglbfnpimkachnpnecjncndgm"
    • But just in case that method does not automatically function the second method is shown above, where you place ; and then the URL https //clients2.google.com/service/update2/crx to explicitly tell NixOS where to install the extension from
  • There are many more options that are natively supported and you can learn about them through man configuration.nix
  • But as shown above there is also an extraOpts option and that is used for policies that are not supported for direct setup, such as the policy to install web-apps

非原生支持的政策

There are hundreds of policies in Chromium based browsers, and not all have direct methods to set them. The extraOpts option allows for the declaration of all the other policies.

There is no single place to find all Chromium policies, but these are some places to look;

  • Commonly used policies are present and documented within man configuration.nix under programs.chromium.
  • You can navigate to chrome://policy and enable "Show policies with no value set" to see all available keys. Clicking a policy name opens its specific definition and usage details.
  • The most up to date policies for Chromium are available in the source code.

視頻播放加速

請確保系統已正確設置 視頻播放加速。檢查 chrome://gpu 以查看 Chromium 是否已啟用硬件加速。

如果視頻播放加速不起作用,請檢查 chrome://flags 中的相關標誌,或使用 CLI 啟用它們:

❄︎ /etc/nixos/configuration.nix
{
  environment.systemPackages = with pkgs; [
    (chromium.override {
      commandLineArgs = [
        "--enable-features=AcceleratedVideoEncoder"
        "--ignore-gpu-blocklist"
        "--enable-zero-copy"
      ];
    })
  ];
}

在某些情況下,chrome://gpu 將顯示「視頻解碼(Video Decode)」已啟用,但「視頻加速信息(Video Acceleration Information)」為空,此時 chrome://media-internals 使用的是 FFmpeg 視頻解碼器(軟件解碼)。如果出現這種情況,請嘗試啟用以下功能:

❄︎ /etc/nixos/configuration.nix
{
  environment.systemPackages = with pkgs; [
    (chromium.override {
      commandLineArgs = [
        "--enable-features=AcceleratedVideoEncoder,VaapiOnNvidiaGPUs,VaapiIgnoreDriverChecks,Vulkan,DefaultANGLEVulkan,VulkanFromANGLE"
        "--enable-features=VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport"
        "--enable-features=UseMultiPlaneFormatForHardwareVideo"
        "--ignore-gpu-blocklist"
        "--enable-zero-copy"
      ];
    })
  ];
}

啟用原生 Wayland 支持

您可以通過將 `NIXOS_OZONE_WL` 環境變量設置為 `1`,在所有基於 Chromium 的應用程序和大多數 Electron 應用程序中啟用原生 Wayland 支持。

啟用 DRM(Widevine 支持)

By default, chromium does not support playing DRM protected media. However, there is a build time flag to include the proprietary Widevine blob from Nixpkgs:

❄︎ /etc/nixos/configuration.nix
{
  environment.systemPackages = with pkgs; [
    (chromium.override { enableWideVine = true; })
  ];
}

KeePassXC support in Flatpak

To enable browser integration between KeePassXC and Chromium-based browsers when running in Flatpak, configure the following filesystem access:

# NativeMessagingHost directory (browser-specific)
# Brave Browser
xdg-config/BraveSoftware/Brave-Browser/NativeMessagingHosts:ro
# Chromium
xdg-config/chromium/NativeMessagingHosts:ro
# Google Chrome
xdg-config/google-chrome/NativeMessagingHosts:ro

# KeePassXC server socket and Nix store
xdg-run/app/org.keepassxc.KeePassXC/org.keepassxc.KeePassXC.BrowserServer
/nix/store:ro

Using libc memory allocator

Chromium may not work when an alternative system-wide memory allocator like scudo is used. To use libc on Chromium, the following firejail wrap is required:

programs.firejail = {
  enable = true;
  wrappedBinaries = {
    chromium = {
      executable = "${pkgs.chromium}/bin/chromium-browser";
      profile = "${pkgs.firejail}/etc/firejail/chromium-browser.profile";
      extraArgs = [
        "--blacklist=/etc/ld-nix.so.preload"
      ];
    };
  };
};