Chromium
安裝
NixOS
添加 chromium 到
systemPackages。
更新瀏覽器政策
在 Chromium 中,可以通過 chrome://policy 訪問政策設置。用戶可以使用這些設置更改影響企業政策的各種功能,例如
- 安裝瀏覽器時自動創建 Web 應用
- 自動查找並下載瀏覽器擴展程序
- 設備離線時啟用或禁用恐龍遊戲
- 禁用瀏覽器擴展程序截屏功能
- 阻止瀏覽器進行所有下載(如果您出於某種原因需要這樣做)
- 以及更多!
A full list of policies can be found at Chrome Enterprise Policy List & Management.
原生支持的政策
NixOS 默認提供了一些可以直接啟用的政策,下面給出一個簡單的示例來理解這些政策的實現方式。
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選項允許您設置主頁打開的網站。
extensions允許您通過一個簡單的擴展程序 ID 列表直接在瀏覽器中下載擴展程序。該列表可以從 Chrome 網上應用商店 獲取,通過打開擴展程序頁面並複製 URL 的最後一部分。
- 然而,示例中還有另一個組件,即擴展程序的下載源。
- 列表中提供的 URL 是 Google 用於管理、檢查和更新擴展程序的連結。
- 因此,只需放置擴展程序 ID 的方法即可工作,如下所示:
"fnpbehpgglbfnpimkachnpnecjncndgm"
- 因此,只需放置擴展程序 ID 的方法即可工作,如下所示:
- 但以防該方法無法自動生效,上面顯示了第二種方法,您需要放置
;,然後放置 URLhttps //clients2.google.com/service/update2/crx,以明確告訴 NixOS 從哪裏安裝擴展程序。
- 但以防該方法無法自動生效,上面顯示了第二種方法,您需要放置
- 還有許多其他原生支持的選項,您可以通過
man configuration.nix了解它們。
- 但如上所示,還有一個
extraOpts選項,用於不支持直接設置的政策,例如安裝網絡應用程式的政策。
非原生支持的政策
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.nixunderprograms.chromium. - You can navigate to
chrome://policyand 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 啟用它們:
{
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 視頻解碼器(軟件解碼)。如果出現這種情況,請嘗試啟用以下功能:
{
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 支持)
默認情況下,chromium 不支持播放受 DRM 保護的媒體。但是,可以通過構建時標誌來包含來自 Nixpkgs 的專有 Widevine blob:
{
environment.systemPackages = with pkgs; [
(chromium.override { enableWideVine = true; })
];
}
Flatpak 中的 KeePassXC 支持
要在 Flatpak 環境下運行 KeePassXC 和基於 Chromium 的瀏覽器時啟用瀏覽器集成,請配置以下文件系統訪問權限:
# 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
使用 libc 內存分配器
當使用諸如 scudo 之類的其他系統級內存分配器時,Chromium 可能無法正常工作。要在 Chromium 上使用 libc,需要以下 firejail 封裝:
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"
];
};
};
};