Jump to content

Niri/zh: Difference between revisions

From Official NixOS Wiki
Ardenet (talk | contribs)
Created page with "然而,由于 niri 不支持 text-input-v1,有时需要通过手动添加 {{ic|<nowiki>--wayland-text-input-version=3</nowiki>}} 标志来启用 text-input-v3,IME 才能正常工作:"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
Created page with "Niri 有一个可选依赖,强烈建议安装(您可阅读 [$1 这篇文章] 以了解更多相关信息)。"
Line 131: Line 131:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<code>wrapProgram</code> 可用于自动添加该标志:
<code>wrapProgram</code> may be used to add the flag automatically:
</div>


{{file|/etc/nixos/configuration.nix|nix|3=
{{file|/etc/nixos/configuration.nix|nix|3=
Line 148: Line 146:
=== XWayland 应用无法正常工作 ===
=== XWayland 应用无法正常工作 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
Niri 有一个可选依赖,强烈建议安装(您可阅读 [https://github.com/niri-wm/niri/wiki/Xwayland 这篇文章] 以了解更多相关信息)。
There is a optional dependency for niri which is highly recommended to install (you can read [https://github.com/niri-wm/niri/wiki/Xwayland this] article to learn more about this)
</div>


{{File|3=environment.systemPackages = with pkgs; [  
{{File|3=environment.systemPackages = with pkgs; [  

Revision as of 16:15, 4 August 2026

警告:显示标题“niri”覆盖了之前的显示标题“Niri”。

niri

Wayland compositor Application

100%
Initial release2023-11-26
Latest release26.04; 25 Apr 2026
StatusActive
Operating SystemLinux, FreeBSD
Language(s)Rust, GLSL
LicenseGNU General Public License v3.0 only
External links
GitHubniri-wm/niri
Bug trackerhttps://github.com/niri-wm/niri/issues
DocumentationOfficial wiki, niri-flake

Niri 是一个可滚动平铺的 Wayland 合成器。

安装

只需启用 programs.niri

❄︎ /etc/nixos/configuration.nix
programs.niri.enable = true;
Note: 无需安装自定义 flake(例如 niri-flake)即可启用 Niri。尽管截至 2025 年,该存储库在搜索引擎中的排名仍然靠前,但只有当您想要使用最新版本的 Niri 或想要用 Nix 语言编写配置时,才需要 niri-flake


⚠︎
Warning: 如果没有进行 配置附加设置,或者在全新安装后,您可能由于缺少 Alacritty 和 fuzzel 等预期程序而无法启动应用程序。请按 Super+Shift+E 退出 niri 并继续执行其中一项操作。


配置

niri 的配置路径为 $XDG_CONFIG_HOME/niri/config.kdl。因此,可以使用 Home Manager 进行配置:

❄︎ ~/.config/home-manager/home.nix
xdg.configFile."niri/config.kdl".source = ./config.kdl;

如果您希望在构建过程中对配置进行验证,可以使用 pkgs.runCommand,用法如下:

❄︎ ~/.config/home-manager/home.nix
xdg.configFile."niri/config.kdl".source =
  pkgs.runCommand "niri-config-checked"
    {
      nativeBuildInputs = [ pkgs.niri ];
    }
    ''
      niri validate --config ${./config.kdl}
      cp ${./config.kdl} $out
    '';


您可能想从默认配置文件开始,如这里所述。

有关 niri 的配置选项,请参阅 此 wiki

Greetd

您可以使用 greeted 配置启动 niri:

❄︎ /etc/nixos/configuration.nix
programs.niri.enable = true;

services.greetd = {
  enable = true;
  settings = {
    default_session = {
      command = "${config.programs.niri.package}/bin/niri-session";
      user = "myuser";
    };
  };
};

# NixOS otherwise injects a stripped PATH via Environment= on the niri.service
# unit which shadows the imported user-manager PATH. Disabling the default
# lets niri inherit the full PATH set up by niri-session.
systemd.user.services.niri.enableDefaultPath = false;

额外设置

示例 systemd 设置 (niri wiki)中所述,您可能需要设置一些额外的服务,包括以下的 SwayidleSwaylockWaybarPolkitSecret Service,以补充常规窗口管理器的功能。其中一些设置也是启用默认配置文件所有功能所必需的。

❄︎ /etc/nixos/configuration.nix
security.polkit.enable = true; # polkit
services.gnome.gnome-keyring.enable = true; # secret service
security.pam.services.swaylock = {};

programs.waybar.enable = true; # top bar
environment.systemPackages = with pkgs; [ alacritty fuzzel swaylock mako swayidle ];

或者使用 Home Manager

❄︎ ~/.config/home-manager/home.nix
programs.alacritty.enable = true; # Super+T in the default setting (terminal)
programs.fuzzel.enable = true; # Super+D in the default setting (app launcher)
programs.swaylock.enable = true; # Super+Alt+L in the default setting (screen locker)
programs.waybar.enable = true; # launch on startup in the default setting (bar)
services.mako.enable = true; # notification daemon
services.swayidle.enable = true; # idle management daemon
services.polkit-gnome.enable = true; # polkit
home.packages = with pkgs; [
  swaybg # wallpaper
];

故障排除

IME 在 Electron 应用中无法正常工作

有一种通用的解决方法,即按照Wayland#Electron_and_Chromium中的说明设置NIXOS_OZONE_WL

❄︎ /etc/nixos/configuration.nix
environment.sessionVariables.NIXOS_OZONE_WL = "1";

然而,由于 niri 不支持 text-input-v1,有时需要通过手动添加 --wayland-text-input-version=3 标志来启用 text-input-v3,IME 才能正常工作:

$ slack --wayland-text-input-version=3

wrapProgram 可用于自动添加该标志:

❄︎ /etc/nixos/configuration.nix
environment.systemPackages = [
  (pkgs.symlinkJoin {
    pname = pkgs.vscode.pname;
    paths = [ pkgs.vscode ];
    buildInputs = [ pkgs.makeWrapper ];
    postBuild = "wrapProgram $out/bin/code --add-flags --wayland-text-input-version=3";
  };)
];

XWayland 应用无法正常工作

Niri 有一个可选依赖,强烈建议安装(您可阅读 这篇文章 以了解更多相关信息)。

❄︎ /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [ 
    xwayland-satellite # xwayland support
];

或者使用 Home Manager

❄︎ ~/.config/home-manager/home.nix
home.packages = with pkgs; [
  xwayland-satellite # xwayland support
];

After you installed xwayland-satellite niri will integrate it out of the box and all of your XWayland apps will function properly.

文件选择器无法正常工作

If you are using xdg-desktop-portal-gnome, it will attempt to use Nautilus as the file picker, which will fail if Nautilus is not installed.

To work around this problem, you can force usage of the gtk or kde portals for file picker instead:

❄︎ /etc/nixos/configuration.nix
xdg.portal.config.niri = {
  "org.freedesktop.impl.portal.FileChooser" = [ "gtk" ]; # or "kde"
};

Waybar 启动两次

When using a configuration option like programs.waybar.enable, waybar may launch twice on Niri. This is because the default Niri config file launches waybar on launch. Remove the spawn-at-startup "waybar" from the config file, or add waybar to your systems packages without using the home-manager option.

另见