# modules/features/desktop/niri.nix — Niri (scrolling-column Wayland
# compositor) with Noctalia Shell, as a wrapped, portable package plus the
# NixOS module that installs it as a login session.
#
# nix run ~/NixDaemon#niri try it nested inside the running desktop (Alt is the modifier)
# daemon.desktop.niri.enable the switch (modules/features/desktop/options.nix)
#
# The settings below become niri's config.kdl at build time (the wrapper runs
# `niri validate` on it, so a bad bind fails the build, not the login) and the
# package carries every program its binds spawn. Keys mirror the Hyprland set
# (modules/home/hypr/defaults.lua) where a Niri or Noctalia counterpart exists.
# Rosé Pine Main: the focus ring is rose #ebbcba on overlay #26233a.
{ self, inputs, ... }:
let theme = import ../../_palette.nix; in
{
perSystem =
{ pkgs, lib, self', ... }:
let
kitty = lib.getExe pkgs.kitty;
zen = lib.getExe' inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default "zen-beta"; # default browser (modules/home/zen.nix)
nautilus = lib.getExe pkgs.nautilus;
screenshot = lib.getExe self'.packages.screenshot;
screenOcr = lib.getExe self'.packages.screen-ocr;
wpctl = "${pkgs.wireplumber}/bin/wpctl";
brightnessctl = lib.getExe pkgs.brightnessctl;
playerctl = lib.getExe pkgs.playerctl;
# a bind that also works on the lock screen (volume, brightness, media)
locked = cmd: _: {
props.allow-when-locked = true;
content.spawn-sh = cmd;
};
# a bind listed in the Mod+Shift+/ hotkey overlay under its own title
titled = title: action: _: {
props.hotkey-overlay-title = title;
content = action;
};
workspaceBinds = lib.foldl' (acc: n: acc // {
"Mod+${toString n}".focus-workspace = n;
"Mod+Shift+${toString n}".move-column-to-workspace = n;
}) { } (lib.range 1 9);
# One niri, parameterised by the Noctalia it starts and the keyboard.
mkNiri =
{
noctaliaPkg,
xkb ? { layout = "us"; },
}:
let
noctalia = lib.getExe noctaliaPkg;
ipc = target: "${noctalia} ipc call ${target}";
in
inputs.wrapper-modules.wrappers.niri.wrap {
inherit pkgs;
settings = {
input = {
keyboard = {
inherit xkb;
};
touchpad = {
tap = _: { };
natural-scroll = _: { };
};
focus-follows-mouse = _: { };
};
layout = {
gaps = 8;
focus-ring = {
width = 2;
active-color = theme.palette.rose;
inactive-color = theme.palette.overlay;
};
border.off = _: { };
preset-column-widths = [
{ proportion = 0.33333; }
{ proportion = 0.5; }
{ proportion = 0.66667; }
];
};
window-rules = [
{
matches = [ { app-id = "^com\\.gabm\\.satty$"; } ];
open-floating = true;
}
{
matches = [ { app-id = "^niri-screensaver$"; } ];
open-fullscreen = true;
}
];
cursor.hide-after-inactive-ms = 1000;
prefer-no-csd = _: { };
hotkey-overlay.skip-at-startup = _: { };
xwayland-satellite.path = lib.getExe pkgs.xwayland-satellite;
# The same session variables the Hyprland side sets (hosts/laptop configuration.nix).
environment = {
ELECTRON_OZONE_PLATFORM_HINT = "auto";
QT_QPA_PLATFORM = "wayland;xcb";
};
spawn-at-startup = [ noctalia ];
binds = {
# apps
"Mod+Return".spawn = [ kitty ];
"Mod+Shift+Return".spawn = [ zen ];
"Mod+Shift+B".spawn = [ zen ];
"Mod+Shift+Alt+B".spawn = [ zen "--private-window" ];
"Mod+Shift+F".spawn = [ nautilus "--new-window" ];
"Mod+Shift+O".spawn-sh = "obsidian"; # unfree, from the system profile (modules/features/workstation.nix)
"Mod+Shift+N".spawn-sh = "${kitty} -e \${EDITOR:-nano}";
# Noctalia
"Mod+Space".spawn-sh = ipc "launcher toggle";
"Mod+Alt+Space".spawn-sh = ipc "launcher toggle";
"Mod+Escape".spawn-sh = ipc "sessionMenu toggle";
"Mod+Ctrl+P".spawn-sh = ipc "sessionMenu toggle";
"Mod+A".spawn-sh = ipc "controlCenter toggle";
"Mod+Comma".spawn-sh = ipc "notifications clear";
"Mod+Ctrl+V".spawn-sh = ipc "launcher clipboard";
"Mod+Ctrl+Space".spawn-sh = ipc "wallpaper toggle";
"Mod+Shift+Escape".spawn-sh = ipc "lockScreen lock";
# windows and columns
"Mod+Q".close-window = _: { };
"Mod+F".maximize-column = _: { };
"Mod+G".fullscreen-window = _: { };
"Mod+Shift+V".toggle-window-floating = _: { };
"Mod+H".focus-column-left = _: { };
"Mod+J".focus-window-down = _: { };
"Mod+K".focus-window-up = _: { };
"Mod+L".focus-column-right = _: { };
"Mod+Left".focus-column-left = _: { };
"Mod+Down".focus-window-down = _: { };
"Mod+Up".focus-window-up = _: { };
"Mod+Right".focus-column-right = _: { };
"Mod+Shift+H".move-column-left = _: { };
"Mod+Shift+J".move-window-down = _: { };
"Mod+Shift+K".move-window-up = _: { };
"Mod+Shift+L".move-column-right = _: { };
"Mod+Shift+Left".move-column-left = _: { };
"Mod+Shift+Down".move-window-down = _: { };
"Mod+Shift+Up".move-window-up = _: { };
"Mod+Shift+Right".move-column-right = _: { };
"Mod+Ctrl+H".set-column-width = "-5%";
"Mod+Ctrl+L".set-column-width = "+5%";
"Mod+Ctrl+J".set-window-height = "-5%";
"Mod+Ctrl+K".set-window-height = "+5%";
# stacking: pull the focused window into the column beside it
# (under the window there), or push it back out into its own column
"Mod+BracketLeft" = titled "Stack window under the column on the left" { consume-or-expel-window-left = _: { }; };
"Mod+BracketRight" = titled "Stack window under the column on the right" { consume-or-expel-window-right = _: { }; };
"Mod+Period" = titled "Pop bottom window out of the column" { expel-window-from-column = _: { }; };
"Mod+W" = titled "Toggle column as tabs" { toggle-column-tabbed-display = _: { }; };
# evening out: preset widths/heights, back to an equal split
"Mod+R" = titled "Cycle column width ⅓ ½ ⅔" { switch-preset-column-width = _: { }; };
"Mod+Shift+R" = titled "Cycle window height ⅓ ½ ⅔" { switch-preset-window-height = _: { }; };
"Mod+Ctrl+R" = titled "Reset window height (even split)" { reset-window-height = _: { }; };
"Mod+Equal" = titled "Column width ½ (even columns)" { set-column-width = "50%"; };
"Mod+Ctrl+F" = titled "Expand column into free space" { expand-column-to-available-width = _: { }; };
"Mod+C" = titled "Centre column" { center-column = _: { }; };
"Mod+WheelScrollDown" = _: {
props.cooldown-ms = 150;
content.focus-workspace-down = _: { };
};
"Mod+WheelScrollUp" = _: {
props.cooldown-ms = 150;
content.focus-workspace-up = _: { };
};
"Mod+O".toggle-overview = _: { };
"Mod+Shift+Slash".show-hotkey-overlay = _: { };
# Both keyboard captures and the Noctalia button use Grim + Satty.
"Print" = titled "Screenshot region → editor" { spawn-sh = "${screenshot} region"; };
"Shift+Print" = titled "Screenshot screen → editor" { spawn-sh = "${screenshot} screen"; };
"Ctrl+Print" = titled "Screenshot region → clipboard" { spawn-sh = "${screenshot} clipboard"; };
"Mod+Print" = titled "Choose screenshot save folder" { spawn-sh = "${screenshot} folder"; };
"Alt+Print" = titled "OCR region → clipboard" { spawn-sh = "${screenOcr}"; };
# media and hardware keys, also on the lock screen
"XF86AudioRaiseVolume" = locked "${wpctl} set-volume -l 1.4 @DEFAULT_AUDIO_SINK@ 5%+";
"XF86AudioLowerVolume" = locked "${wpctl} set-volume -l 1.4 @DEFAULT_AUDIO_SINK@ 5%-";
"XF86AudioMute" = locked "${wpctl} set-mute @DEFAULT_AUDIO_SINK@ toggle";
"XF86AudioMicMute" = locked "${wpctl} set-mute @DEFAULT_AUDIO_SOURCE@ toggle";
"XF86MonBrightnessUp" = locked "${brightnessctl} set 5%+";
"XF86MonBrightnessDown" = locked "${brightnessctl} set 5%-";
"XF86AudioPlay" = locked "${playerctl} play-pause";
"XF86AudioPause" = locked "${playerctl} play-pause";
"XF86AudioNext" = locked "${playerctl} next";
"XF86AudioPrev" = locked "${playerctl} previous";
"Mod+Shift+E".quit = _: { }; # niri asks for confirmation
} // workspaceBinds;
};
};
in
{
# Gradia, the screenshot editor the Print binds open, with its Censor tool
# replaced by a secure blur (_gradia-secure-blur.patch). Upstream
# pixelates in fixed 8 px blocks with the size slider greyed out, which
# leaves large text readable. Patched, the slider sets the strength: the
# area is averaged into cells 4× the slider value (12–100 px, 56 by
# default), each cell gets random brightness noise so depixelation tools
# can't match the true averages, and it is scaled back up smoothly.
# Still not zero-leak: for secrets, a filled rectangle is the safe choice.
# Shared with home-manager (modules/home/session.nix) so the launcher
# entry runs the same build.
packages.gradia = pkgs.gradia.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [ ./_gradia-secure-blur.patch ];
});
# packages.niri is what anyone running the flake gets (US layout, the
# neutral Noctalia); packages.niri-daemon is the author's (his keyboard
# options, packages.noctalia-daemon). The generic host builds its own
# with its keyboard layout through legacyPackages.mkNiri.
packages.niri = mkNiri { noctaliaPkg = self'.packages.noctalia; };
packages.niri-daemon = mkNiri {
noctaliaPkg = self'.packages.noctalia-daemon;
xkb = {
layout = "us";
options = "compose:caps,shift:both_capslock_cancel"; # as services.xserver.xkb
};
};
legacyPackages.mkNiri = mkNiri;
};
flake.nixosModules.desktop-niri =
{ config, lib, pkgs, ... }:
{
config = lib.mkIf config.daemon.desktop.niri.enable {
# nixpkgs' module registers the session for tuigreet and adds the
# GNOME portal Niri documents; the package is the wrapped one above.
programs.niri = {
enable = true;
package = config.daemon.desktop.niri.package;
};
# Noctalia's battery widget reads UPower (nixpkgs' module leaves it off).
services.upower.enable = true;
# nixpkgs' portal config for niri names the gtk implementations for
# Access, FileChooser and Notification; keep that portal installed even
# when the Hyprland side (which also adds it) is switched off.
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
};
};
}