- Nix 100%
Niri Nix
A flake for configuring the Niri window manager with Nix.
The options are described in nixos-options.md and home-options.md respectfully.
Installation
To install the flake, add the following input to your flake.nix:
niri-nix = {
url = "git+https://codeberg.org/BANanaD3V/niri-nix";
};
The flake provides both NixOS and home-manager modules.
imports = [ inputs.niri-nix.nixosModules.default ]; # For NixOS
imports = [ inputs.niri-nix.homeModules.default ]; # For home-manager
Overlays
The flake provides an overlay and a binary cache for packages. The packages are
niri-unstable and xwayland-satellite-unstable.
The binary cache is located at https://niri-nix.cachix.org, the public key is
niri-nix.cachix.org-1:SvFtqpDcf7Sm1SMJdby1/+Y+6f3Yt3/3PMcSTKPJNJ0=.
Niri unstable
To use niri unstable, add the overlay and the binary cache and then set
programs.niri.package for the NixOS module and
wayland.windowManager.niri.package for home-manager. You do not need to set
the home-manager package if you're using the NixOS module to intall niri.
Important
By using the binary cache you are trusting me not to compromise your system and serve you malicious packages. The module will never automatically add the cache. The default cache priority is
41, which is belowcache.nixos.org. Proceed at your own discretion.
{inputs, pkgs, ...}: {
nix = {
substituters = [
"https://niri-nix.cachix.org"
];
trusted-public-keys = [
"niri-nix.cachix.org-1:SvFtqpDcf7Sm1SMJdby1/+Y+6f3Yt3/3PMcSTKPJNJ0="
];
};
nixpkgs.overlays = [ inputs.niri-nix.overlays.niri-nix ];
programs.niri.package = pkgs.niri-unstable;
}
NixOS module
UWSM
The NixOS module allows you to use UWSM
to launch Niri. To do so, enable programs.niri.withUWSM.
XDG
The NixOS module automatically enables XDG portal configuration for you. To
disable the functionality, disable programs.niri.withXDG.
home-manager module
Niri configuration
To configure niri you generally should use the provided home-manager options,
wayland.windowManager.niri.settings and
wayland.windowManager.niri.extraConfig. The options follow the
RFC 42.
This means that the options are freeform and checked during build by running
niri validate. The extraConfig value is appended after settings.
You can disable validation by setting
wayland.windowManager.niri.validation.enable to false.
All KDL attributes are exposed to Nix. For writing regular nodes, use the nix syntax. For arguments and properties, see below.
- You can set arguments by using the
_argsfield:
output = [
{
_args = ["DP-0"];
mode = "1920x1080@60";
}
{
_args = ["DP-1"];
mode = "2560x1440@60";
}
];
This results in the following KDL config:
output"DP-0"{ mode"1920x1080@60"}output"DP-1"{ mode"2560x1440@60"}- For properties you can similarly use
the
_propsfield. Let us try to extend our previous output config:
output = [
{
_args = ["DP-0"];
mode = "1920x1080@60";
position._props = {
x = 0;
y = 0;
};
}
{
_args = ["DP-1"];
mode = "2560x1440@60";
position._props = {
x = 1920;
y = 0;
};
}
];
The resulting config will now be as follows:
output"DP-0"{ mode"1920x1080@60" positionx=0y=0}output"DP-1"{ mode"2560x1440@60" positionx=1920y=0}- For an array of children with same property names, for example the
preset-column-widths, use the_childrenfield:
layout.preset-column-widths._children = [
{proportion = 0.33333;}
{proportion = 0.5;}
{proportion = 0.66667;}
{proportion = 1.0;}
];
The resulting KDL:
layout{ preset-column-widths{ proportion0.333330 proportion0.500000 proportion0.666670 proportion1.000000}}- The library also provides a way to set raw values, for example, to use
regular expressions. To do so, use the
_rawattribute:
window-rule = [
{
match = {
_props.app-id._raw = ''r#"^org\.telegram\.desktop$"#'';
};
block-out-from = "screen-capture";
}
];
This should be everything required to fully configure Niri.
For an example configuration, see the options reference
Usage without home-manager
If you do not wish to use home-manager, the flake provides a lib output
containing all the necessary functions to configure Niri.
{ inputs, pkgs, ... }: let
inherit (inputs.niri-nix.lib) validatedConfigFor mkNiriKDL;
inherit (inputs.niri-nix.packages.${pkgs.stdenv.hostPlatform.system}) niri-unstable;
myConfig = {
output = [
{
_args = ["DP-0"];
mode = "1920x1080@60";
}
{
_args = ["DP-1"];
mode = "2560x1440@60";
}
];
};
in {
# Obviously replacing xdg.configFile with your own needed function.
xdg.configFile."niri/config-validated.kdl".text = validatedConfigFor niri-unstable (mkNiriKDL myConfig); # Config example with validation (`niri validate`)
xdg.configFile."niri/config-plain.kdl".text = mkNiriKDL myConfig; # Config example without validation
}
Credits
- home-manager for the initial
toKDLfunction - Naxdy/niri for the required home-manager
systemdoption and slighttoKDLimprovements. - niri-flake for some code snippets (portals, etc).