Files
komorebi/nix/nixos-module.nix
T
LGUG2Z a86e2bdc63 build(nix): a NixOS module for komorebi
On NixOS, running komorebi should take one flake input and one module line. The
flake exports `services.komorebi` as nixosModules.default (and .komorebi). It
adds the flake's overlay, which gains komorebi-full, installs komorebi and
komorebic, and runs the daemon in every Plasma session as a systemd user unit,
wanted by plasma-workspace.target and ordered after plasma-core.target, which
Plasma orders after KWin. systemd starts a daemon that fails again; the exit
status of a SIGTERM (130) counts as success, so a stopped unit is not failed.
The unit's PATH is the one a terminal in the session has, instead of the few
store paths NixOS gives a unit.

The options are enable, package, logLevel and a read-only execStart, the command
line the unit runs. There is no configFile: the daemon reads no configuration
file yet, and an option that linked one would do nothing.

nixos-module-eval evaluates seven scenarios as real NixOS systems and checks
their assertions, the unit and execStart, with builtins.tryEval for the two that
must not evaluate. Nothing in it builds a Linux package, so it runs on a Mac as
well.

The VM nodes import the module, so every suite runs komorebi as the module
installs it. The headless node's komorebi@NAME runs execStart, which has
--log-level, so the nodes set logLevel to debug and the suites stop passing it;
latency, which times the daemon, keeps the default level. The session node
starts the module's unit at login; render-smoke turns it off, since a tiled
terminal would cover the desktop it looks at. A new fast suite, vm-module, logs
in to Plasma and checks that the unit runs the daemon with the module's log
level and PATH, that a window opened in the session is tiled, that a killed
daemon is started again, and that a stop is not a failure.

docs/installation.md covers NixOS first, and building from source on other
distributions. There is no binary cache: the Komorebi license does not allow
third parties to redistribute binaries.
2026-10-28 07:20:37 -07:00

97 lines
3.3 KiB
Nix

# `services.komorebi`: komorebi in the Plasma session of every user of a NixOS machine. The flake
# exports this module as `nixosModules.default` and `nixosModules.komorebi`, together with its
# overlay, which provides `pkgs.komorebi-full` (see docs/installation.md). What the module
# guarantees, and what enforces each guarantee, is in docs/dev/ARCHITECTURE.md; its tests are
# nix/tests/nixos-module.nix and the VM suite `module`.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.komorebi;
in
{
options.services.komorebi = {
enable = lib.mkEnableOption "komorebi, the tiling window manager, in the Plasma session of every user";
package = lib.mkPackageOption pkgs "komorebi-full" {
extraDescription = ''
It must have `bin/komorebi`, which the unit runs, and `bin/komorebic`. The module installs
both in the system profile.
'';
};
logLevel = lib.mkOption {
type = lib.types.enum [
"error"
"warn"
"info"
"debug"
"trace"
];
default = "info";
description = ''
How much the daemon logs: its `--log-level`. The log goes to the journal of the unit
(`journalctl --user -u komorebi`) and to the daemon's log files, which `komorebic log`
follows.
'';
};
execStart = lib.mkOption {
type = lib.types.str;
readOnly = true;
description = ''
The command line the unit starts komorebi with: `bin/komorebi` of `package`, with
`logLevel`. The module sets it, and setting it anywhere else is an error. A unit of your
own that runs komorebi somewhere else, as the VM tests do in their headless sessions,
starts it with this, the way the module does.
'';
};
};
config = lib.mkMerge [
{
services.komorebi.execStart = "${lib.getExe' cfg.package "komorebi"} --log-level ${cfg.logLevel}";
}
(lib.mkIf cfg.enable {
assertions = [
{
assertion = config.services.desktopManager.plasma6.enable;
message = ''
services.komorebi needs Plasma 6: komorebi runs in a Plasma Wayland session, and the
session starts it. Set services.desktopManager.plasma6.enable = true.
'';
}
];
environment.systemPackages = [ cfg.package ];
# A user unit, so it runs for every user who logs in to Plasma. plasma-workspace.target is
# the target of a Plasma session's services, and plasma-core.target, which it requires, is
# ordered after KWin's service: the daemon exits when KWin is not on the session bus.
systemd.user.services.komorebi = {
description = "komorebi, the tiling window manager";
wantedBy = [ "plasma-workspace.target" ];
after = [ "plasma-core.target" ];
# NixOS gives a unit a PATH made of a few store paths; this is the PATH a terminal in the
# user's session has
enableDefaultPath = false;
environment.PATH = lib.concatStringsSep ":" [
"/run/wrappers/bin"
"/etc/profiles/per-user/%u/bin"
"/run/current-system/sw/bin"
];
serviceConfig = {
ExecStart = cfg.execStart;
Restart = "on-failure";
# what komorebi exits with when it is stopped with SIGTERM, as systemd stops a unit
SuccessExitStatus = 130;
};
};
})
];
}