feat(wm): JSON schemas, and the module's typed options

komorebi.json is described as a JSON Schema, made from the Rust types that read
it: komorebic prints the schema of komorebi.json, of an applications.json, of a
notification and of a message, and the daemon answers the same four questions on
its socket. schema.json and schema.asc.json are committed (just jsonschema).

The module's config option is typed from the schema: schemars-nixgen makes
nix/komorebi-options.nix from schema.json (just nixgen), so a layout komorebi
does not have, or a value of the wrong kind, does not evaluate. The module
writes config as a komorebi.json and gives it to the daemon with --config.
configFile and the file the module writes are checked against the schema when
the system is built. applicationSpecificConfiguration takes files from GitHub,
and there are none by default, since no community file for Plasma is known.

Two checks keep the generated files honest without the tools that make them.
schema-fresh compares the schemas with what komorebic prints, and the hash on
the first line of the options with the schema. nix-options-validation evaluates
the options against the example configuration, written in Nix and in JSON.

nixos-module-eval also evaluates the module with the sources turned off: with
applicationSpecificConfiguration.enable = false the sources are left out of the
config that is written, and with no config either there is nothing to write and
the unit passes no --config. ARCHITECTURE has the guarantee row that names the
two checks.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:37 -07:00
1 parent ed34286bca
commit 3a3a0f8f24
29 files changed
+2754 -49

No files matched your search

+514
View File
@@ -0,0 +1,514 @@
# schema-sha256: 2bb6a47d645d5027d15ea70545473ac3dd417e8a2d7ac932d3c593d71a539dbd
{ lib, ... }:
let
defaultLayout = (
lib.types.enum [
"BSP"
"Columns"
"Rows"
"VerticalStack"
"HorizontalStack"
"UltrawideVerticalStack"
"Grid"
"RightMainVerticalStack"
"Scrolling"
]
);
floatingLayerBehaviour = (
lib.types.enum [
"Tile"
"Float"
]
);
idWithIdentifier = (
lib.types.submodule {
options = {
id = lib.mkOption {
type = lib.types.str;
description = "Target identifier";
};
kind = lib.mkOption {
type = (
lib.types.enum [
"Exe"
"Class"
"Title"
"Path"
]
);
description = "Kind of identifier to target";
};
matching_strategy = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Legacy"
"Equals"
"StartsWith"
"EndsWith"
"Contains"
"Regex"
"DoesNotEndWith"
"DoesNotStartWith"
"DoesNotEqual"
"DoesNotContain"
]
)
);
default = null;
description = "Matching strategy to use";
};
};
}
);
layoutOptions = (
lib.types.submodule {
options = {
column_ratios = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf (lib.types.nullOr lib.types.number)));
default = null;
description = "Column width ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Columns layout: ratios for each column width\n- Used by Grid layout: ratios for column widths\n- Used by BSP, VerticalStack, RightMainVerticalStack: column_ratios[0] as primary split ratio\n- Used by HorizontalStack: column_ratios[0] as primary split ratio (top area height)\n- Used by UltrawideVerticalStack: column_ratios[0] as center ratio, column_ratios[1] as left ratio\n\nColumns without a ratio share remaining space equally.\nExample: `[0.3, 0.4, 0.3]` for 30%-40%-30% columns";
};
grid = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.submodule {
options = {
rows = lib.mkOption {
type = lib.types.int;
description = "Maximum number of rows per grid column";
};
};
}
)
);
default = null;
description = "Options related to the Grid layout";
};
row_ratios = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf (lib.types.nullOr lib.types.number)));
default = null;
description = "Row height ratios (up to MAX_RATIOS values between 0.1 and 0.9)\n\n- Used by Rows layout: ratios for each row height\n- Used by Grid layout: ratios for row heights\n\nRows without a ratio share remaining space equally.\nExample: `[0.5, 0.5]` for 50%-50% rows";
};
scrolling = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.submodule {
options = {
center_focused_column = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = null;
description = "With an odd number of visible columns, keep the focused window column centered";
};
columns = lib.mkOption {
type = lib.types.int;
description = "Desired number of visible columns (default: 3)";
};
};
}
)
);
default = null;
description = "Options related to the Scrolling layout";
};
};
}
);
matchingRule = (
lib.types.oneOf [
idWithIdentifier
(lib.types.listOf idWithIdentifier)
]
);
pathBuf = lib.types.str;
placement = (
lib.types.enum [
"None"
"Center"
"CenterAndResize"
]
);
rect = (
lib.types.submodule {
options = {
bottom = lib.mkOption {
type = lib.types.int;
description = "Height of the rectangle (from the top point)";
};
left = lib.mkOption {
type = lib.types.int;
description = "Left point of the rectangle";
};
right = lib.mkOption {
type = lib.types.int;
description = "Width of the recentangle (from the left point)";
};
top = lib.mkOption {
type = lib.types.int;
description = "Top point of the rectangle";
};
};
}
);
windowContainerBehaviour = (
lib.types.enum [
"Create"
"Append"
]
);
in
{
options.komorebi = lib.mkOption {
type = lib.types.submodule {
options = {
app_specific_configuration_path = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.oneOf [
pathBuf
(lib.types.listOf pathBuf)
]
)
);
default = null;
description = "Path to an applications.json, or a list of them, with rules for the applications that\nneed them: which windows to ignore, to manage and to float";
};
cross_boundary_behaviour = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Workspace"
"Monitor"
]
)
);
default = "Monitor";
description = "Determine what happens when an action is called on a window at a monitor boundary";
};
cross_monitor_move_behaviour = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Swap"
"Insert"
"NoOp"
]
)
);
default = "Swap";
description = "Determine what happens when a window is moved across a monitor boundary";
};
default_container_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = 5;
description = "Global default container padding";
};
default_workspace_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = 5;
description = "Global default workspace padding";
};
display_index_preferences = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf lib.types.str));
default = null;
description = "Set display index preferences";
};
float_override = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = false;
description = "Enable or disable float override, which makes it so every new window opens in floating mode";
};
float_override_placement = lib.mkOption {
type = (lib.types.nullOr placement);
default = null;
description = "Determines the `Placement` to be used when spawning a window with float override active";
};
float_rule_placement = lib.mkOption {
type = (lib.types.nullOr placement);
default = null;
description = "Determines the `Placement` to be used when spawning a window that matches a\n'floating_applications' rule";
};
floating_applications = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf matchingRule));
default = null;
description = "Identify applications which should be managed as floating windows";
};
floating_layer_behaviour = lib.mkOption {
type = (lib.types.nullOr floatingLayerBehaviour);
default = "Tile";
description = "Determines what happens on a new window when on the `FloatingLayer`";
};
floating_layer_placement = lib.mkOption {
type = (lib.types.nullOr placement);
default = "Center";
description = "Determines the `Placement` to be used when spawning a window on the floating layer with the\n`FloatingLayerBehaviour` set to `FloatingLayerBehaviour::Float`";
};
floating_window_aspect_ratio = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.oneOf [
(lib.types.enum [
"Ultrawide"
"Widescreen"
"Standard"
])
(lib.types.listOf lib.types.int)
]
)
);
default = null;
description = "Aspect ratio to resize with when toggling floating mode for a window";
};
global_work_area_offset = lib.mkOption {
type = (lib.types.nullOr rect);
default = null;
description = "Global work area (space used for tiling) offset";
};
ignore_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf matchingRule));
default = null;
description = "Individual window floating rules";
};
layout_defaults = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.attrsOf (
lib.types.submodule {
options = {
layout_options = lib.mkOption {
type = (lib.types.nullOr layoutOptions);
default = null;
description = "Default layout options for this layout";
};
layout_options_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf layoutOptions));
default = null;
description = "Threshold-based layout options rules in the format of threshold => options.\nWhen container count >= threshold, the highest matching threshold's options\nfully replace the base `layout_options`.";
};
};
}
)
)
);
default = null;
description = "Per-layout default options and rules, keyed by layout name.\nApplied as fallback when a workspace does not define its own layout_options or layout_options_rules.\nIf a workspace defines either setting, all global defaults for that layout are completely replaced.";
};
manage_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf matchingRule));
default = null;
description = "Individual window force-manage rules";
};
monitors = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.listOf (
lib.types.submodule {
options = {
container_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = null;
description = "Container padding";
};
floating_layer_behaviour = lib.mkOption {
type = (lib.types.nullOr floatingLayerBehaviour);
default = "Tile";
description = "Determine what happens to a new window when the Floating workspace layer is active";
};
window_based_work_area_offset = lib.mkOption {
type = (lib.types.nullOr rect);
default = null;
description = "Window based work area offset";
};
window_based_work_area_offset_limit = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = 1;
description = "Open window limit after which the window based work area offset will no longer be applied";
};
window_hiding_position = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"BottomLeft"
"BottomRight"
]
)
);
default = null;
description = "Accepted so that a configuration written for another platform loads, and ignored: there is\nno hiding position on KDE Plasma";
};
work_area_offset = lib.mkOption {
type = (lib.types.nullOr rect);
default = null;
description = "Monitor-specific work area offset";
};
workspace_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = null;
description = "Workspace padding (default: global)";
};
workspaces = lib.mkOption {
type = (
lib.types.listOf (
lib.types.submodule {
options = {
apply_window_based_work_area_offset = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = true;
description = "Apply this monitor's window-based work area offset";
};
container_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = null;
description = "Container padding (default: global)";
};
float_override = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = false;
description = "Enable or disable float override, which makes it so every new window opens in floating mode";
};
floating_layer_behaviour = lib.mkOption {
type = (lib.types.nullOr floatingLayerBehaviour);
default = "Tile";
description = "Determine what happens to a new window when the Floating workspace layer is active";
};
layout = lib.mkOption {
type = (lib.types.nullOr defaultLayout);
default = "BSP";
description = "Layout";
};
layout_flip = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Horizontal"
"Vertical"
"HorizontalAndVertical"
]
)
);
default = null;
description = "Specify an axis on which to flip the selected layout";
};
layout_options = lib.mkOption {
type = (lib.types.nullOr layoutOptions);
default = null;
description = "Layout-specific options";
};
layout_options_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf layoutOptions));
default = null;
description = "Threshold-based layout options rules in the format of threshold => options.\nWhen container count >= threshold, the highest matching threshold's options\nfully replace the base `layout_options`.\nThis follows the same threshold logic as `layout_rules`.";
};
layout_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf defaultLayout));
default = null;
description = "Layout rules in the format of threshold => layout";
};
name = lib.mkOption {
type = lib.types.str;
description = "Name";
};
tile = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = true;
description = "Enable or disable tiling for the workspace";
};
window_container_behaviour = lib.mkOption {
type = (lib.types.nullOr windowContainerBehaviour);
default = "Create";
description = "Determine what happens when a new window is opened";
};
window_container_behaviour_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf windowContainerBehaviour));
default = null;
description = "Window container behavior rules in the format of threshold => behavior";
};
work_area_offset = lib.mkOption {
type = (lib.types.nullOr rect);
default = null;
description = "Workspace specific work area offset";
};
work_area_offset_rules = lib.mkOption {
type = (lib.types.nullOr (lib.types.attrsOf rect));
default = null;
description = "Work area offset rules in the format of threshold => Rect (default: None)";
};
workspace_padding = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = null;
description = "Workspace padding (default: global)";
};
};
}
)
);
description = "Workspace configurations";
};
};
}
)
)
);
default = null;
description = "Monitor and workspace configurations";
};
monocle_focus_behaviour = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Cycle"
"NoOp"
]
)
);
default = "NoOp";
description = "Determine what happens when focusing in a direction while a monocle container is active";
};
mouse_follows_focus = lib.mkOption {
type = (lib.types.nullOr lib.types.bool);
default = true;
description = "Enable or disable mouse follows focus";
};
resize_delta = lib.mkOption {
type = (lib.types.nullOr lib.types.int);
default = 50;
description = "Delta to resize windows by";
};
tabbed_applications = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf lib.types.str));
default = null;
description = "Accepted so that a configuration written for another platform loads, and ignored: a KWin\nwindow has no native tabs";
};
titleless_applications = lib.mkOption {
type = (lib.types.nullOr (lib.types.listOf lib.types.str));
default = null;
description = "Accepted so that a configuration written for another platform loads, and ignored: a KWin\nwindow is always a window";
};
toggle_float_placement = lib.mkOption {
type = (lib.types.nullOr placement);
default = "CenterAndResize";
description = "Determines the placement of a new window when toggling to float";
};
unmanaged_window_operation_behaviour = lib.mkOption {
type = (
lib.types.nullOr (
lib.types.enum [
"Op"
"NoOp"
]
)
);
default = "Op";
description = "Determine what happens when commands are sent while an unmanaged window is in the foreground";
};
window_container_behaviour = lib.mkOption {
type = (lib.types.nullOr windowContainerBehaviour);
default = "Create";
description = "Determine what happens when a new window is opened";
};
};
};
default = { };
description = "komorebi for KDE Plasma configuration";
};
}
+191 -7
View File
@@ -11,6 +11,83 @@
}:
let
cfg = config.services.komorebi;
jsonFormat = pkgs.formats.json { };
# The options `just nixgen` makes from `schema.json`, which type `config`
komorebiOptionsModule = import ./komorebi-options.nix { inherit lib; };
# the Nix module system uses null for an optional field that is not set, and the schema wants
# the field to be absent
filterNulls =
value:
if value == null then
null
else if builtins.isList value then
map filterNulls (builtins.filter (x: x != null) value)
else if builtins.isAttrs value then
lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value)
else
value;
# A komorebi.json, checked against the schema the Rust types make (`schema.json`). Comment
# lines are taken out first: komorebi reads JSON with comments, and the schema checker does not.
validateJsonFile =
{
name,
jsonFile,
}:
pkgs.runCommand "validated-${name}" { nativeBuildInputs = [ pkgs.check-jsonschema ]; } ''
grep -v '^\s*//' ${jsonFile} > clean.json
check-jsonschema --schemafile ${../schema.json} clean.json
cp clean.json $out
'';
fetchAppSpecificSource =
source:
pkgs.fetchurl {
url = "https://raw.githubusercontent.com/${source.owner}/${source.repo}/${source.rev}/${source.path}";
inherit (source) hash;
};
applicationSpecificConfigFiles = map fetchAppSpecificSource cfg.applicationSpecificConfiguration.sources;
# one file is a path, several are a list of paths
appSpecificPaths =
if builtins.length applicationSpecificConfigFiles == 1 then
"${builtins.head applicationSpecificConfigFiles}"
else
map (f: "${f}") applicationSpecificConfigFiles;
shouldUseAppSpecific =
cfg.applicationSpecificConfiguration.enable && applicationSpecificConfigFiles != [ ];
# What `config` and `applicationSpecificConfiguration` make: the komorebi.json as an attribute
# set, with no null in it, or null when there is nothing to write
configAttrs =
if cfg.config == null && !shouldUseAppSpecific then
null
else
filterNulls (
(if cfg.config == null then { } else cfg.config)
// lib.optionalAttrs shouldUseAppSpecific { app_specific_configuration_path = appSpecificPaths; }
);
# the file the daemon is given: the one `configFile` names, or the one the options make, each
# checked against the schema
komorebiConfigFile =
if cfg.configFile != null then
validateJsonFile {
name = "komorebi.json";
jsonFile = cfg.configFile;
}
else if configAttrs != null then
validateJsonFile {
name = "komorebi.json";
jsonFile = jsonFormat.generate "komorebi.json" configAttrs;
}
else
null;
in
{
options.services.komorebi = {
@@ -44,12 +121,110 @@ in
default = null;
example = lib.literalExpression "./komorebi.json";
description = ''
The `komorebi.json` the daemon is configured by. The unit starts komorebi with it, as
`--config`, in place of the `komorebi.json` the daemon looks for in `~/.config/komorebi`
The `komorebi.json` the daemon is configured by, checked against the schema of
`komorebi.json` when the system is built. The unit starts komorebi with it, as `--config`,
in place of the `komorebi.json` the daemon looks for in `~/.config/komorebi`
(`$KOMOREBI_CONFIG_HOME`). The file is in the Nix store, so it does not change under the
daemon: a new file is read when the daemon starts again. `komorebic configuration` still
shows the file of the config home, which the daemon does not read while this is set. With
no `configFile`, the daemon reads the file of the config home, if there is one.
neither `configFile` nor `config`, the daemon reads the file of the config home, if there
is one. Ignored by `config`, which is ignored when this is set.
'';
};
config = lib.mkOption {
type = lib.types.nullOr komorebiOptionsModule.options.komorebi.type;
default = null;
example = lib.literalExpression ''
{
default_workspace_padding = 15;
monitors = [
{
workspaces = [
{ name = "web"; layout = "BSP"; }
{ name = "code"; layout = "Columns"; }
];
}
];
}
'';
description = ''
The configuration of komorebi, written as Nix: every key of `komorebi.json`, typed from
the schema, so a layout that does not exist or a value of the wrong kind does not
evaluate. The module writes it as a `komorebi.json`, checks that against the schema, and
starts komorebi with it as `--config`. Ignored if `configFile` is set. A key you leave
out is the default the schema gives it, if it gives one, and the daemon's own otherwise.
'';
};
applicationSpecificConfiguration = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to use the sources of application specific configuration.";
};
sources = lib.mkOption {
type = lib.types.listOf (
lib.types.submodule {
options = {
owner = lib.mkOption {
type = lib.types.str;
description = "GitHub repository owner.";
example = "LGUG2Z";
};
repo = lib.mkOption {
type = lib.types.str;
description = "GitHub repository name.";
example = "komorebi-application-specific-configuration";
};
rev = lib.mkOption {
type = lib.types.str;
description = "Git revision (commit hash, tag, or branch).";
example = "09ebdcd95780b168cecde2f2d49096a58e91365f";
};
path = lib.mkOption {
type = lib.types.str;
default = "applications.json";
description = "Path to the JSON file within the repository.";
};
hash = lib.mkOption {
type = lib.types.str;
description = "SHA256 hash of the file, for reproducibility.";
example = "sha256-gfYubJpVEU6vxdd/vqujQhQX8mdAEE9ImugqdIyTQKk=";
};
};
}
);
default = [ ];
description = ''
Files of application specific configuration, each fetched from GitHub, which the module
gives the daemon as `app_specific_configuration_path` of the configuration it writes
(it replaces the value `config` has for that key). There are none by default: no
community file for KDE Plasma is known. Ignored when `configFile` is set.
'';
example = lib.literalExpression ''
[
{
owner = "myuser";
repo = "my-komorebi-rules";
rev = "0123456789abcdef0123456789abcdef01234567";
path = "applications.json";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
]
'';
};
};
internal.configAttrs = lib.mkOption {
type = lib.types.nullOr lib.types.attrs;
readOnly = true;
internal = true;
description = ''
What `config` and `applicationSpecificConfiguration` make, before it is written as JSON:
the `komorebi.json` as an attribute set with no null in it, or null when neither is set.
The tests of the module read it, so that they need not build the file.
'';
};
@@ -58,8 +233,8 @@ in
readOnly = true;
description = ''
The command line the unit starts komorebi with: `bin/komorebi` of `package`, with
`logLevel`, and with `--config` and `configFile` when that is set. The module sets it,
and setting it anywhere else is an error. A unit of your own that runs komorebi somewhere
`logLevel`, and with `--config` and the checked `komorebi.json` when `configFile` or
`config` is set. 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.
'';
@@ -74,11 +249,12 @@ in
"--log-level"
cfg.logLevel
]
++ lib.optionals (cfg.configFile != null) [
++ lib.optionals (komorebiConfigFile != null) [
"--config"
"${cfg.configFile}"
"${komorebiConfigFile}"
]
);
services.komorebi.internal.configAttrs = configAttrs;
}
(lib.mkIf cfg.enable {
@@ -92,6 +268,14 @@ in
}
];
warnings =
lib.optional (
cfg.configFile != null && cfg.config != null
) "services.komorebi.config is ignored: services.komorebi.configFile is set."
++
lib.optional (cfg.configFile != null && cfg.applicationSpecificConfiguration.sources != [ ])
"services.komorebi.applicationSpecificConfiguration is ignored: services.komorebi.configFile is set.";
environment.systemPackages = [ cfg.package ];
# A user unit, so it runs for every user who logs in to Plasma. plasma-workspace.target is
+57
View File
@@ -0,0 +1,57 @@
# `nix-options-validation`: the options `just nixgen` makes from `schema.json`, evaluated against
# the example configuration, whose JSON is checked against the schema, and against the example
# file of the docs. Run with `nix build -f nix/tests/default.nix`, or as a check of the flake.
{
pkgs ? import <nixpkgs> { },
}:
let
lib = pkgs.lib;
# the Nix module system uses null for an optional field that is not set, and the schema wants
# the field to be absent
filterNulls =
value:
if value == null then
null
else if builtins.isList value then
map filterNulls (builtins.filter (x: x != null) value)
else if builtins.isAttrs value then
lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value)
else
value;
evaluated =
(lib.evalModules {
modules = [
(import ../komorebi-options.nix)
(import ./komorebi-example.nix)
];
}).config.komorebi;
evaluatedJson = pkgs.writeText "komorebi-example-from-nix.json" (
builtins.toJSON (filterNulls evaluated)
);
exampleJson = ../../docs/komorebi.example.json;
schema = ../../schema.json;
in
pkgs.runCommand "nix-options-validation"
{
nativeBuildInputs = [
pkgs.check-jsonschema
pkgs.jq
];
}
''
echo "Validating the example, written in Nix, against the schema..."
check-jsonschema --schemafile ${schema} ${evaluatedJson}
echo "Validating the example file of the docs against the schema..."
check-jsonschema --schemafile ${schema} ${exampleJson}
echo "Checking that the two examples say the same..."
jq -e --slurpfile example ${exampleJson} 'contains($example[0])' ${evaluatedJson} > /dev/null
echo "All validations passed!"
touch $out
''
+55
View File
@@ -0,0 +1,55 @@
# Nix equivalent of docs/komorebi.example.json
# This tests that users can write the exact same config in Nix
{ ... }:
{
komorebi = {
app_specific_configuration_path = "$HOME/.config/komorebi/applications.json";
cross_monitor_move_behaviour = "Insert";
default_workspace_padding = 15;
default_container_padding = 15;
floating_window_aspect_ratio = "Widescreen";
floating_layer_behaviour = "Float";
resize_delta = 100;
ignore_rules = [ ];
floating_applications = [ ];
manage_rules = [ ];
monitors = [
{
workspaces = [
{
name = "I";
layout = "BSP";
}
{
name = "II";
layout = "VerticalStack";
}
{
name = "III";
layout = "HorizontalStack";
}
{
name = "IV";
layout = "UltrawideVerticalStack";
}
{
name = "V";
layout = "Rows";
}
{
name = "VI";
layout = "Grid";
}
{
name = "VII";
layout = "RightMainVerticalStack";
}
{
name = "VIII";
layout = "Scrolling";
}
];
}
];
};
}
+203 -2
View File
@@ -83,6 +83,131 @@ let
}
);
withConfig = eval {
imports = [ plasma ];
services.komorebi = {
enable = true;
config = {
default_workspace_padding = 20;
window_container_behaviour = "Append";
float_override_placement = "Center";
monocle_focus_behaviour = "Cycle";
monitors = [
{
floating_layer_behaviour = "Tile";
workspaces = [
{
name = "web";
layout = "BSP";
}
{
name = "code";
layout = "Columns";
window_container_behaviour_rules."2" = "Append";
float_override = false;
floating_layer_behaviour = "Float";
}
];
}
];
};
};
};
# a layout komorebi does not have
badLayout = eval {
imports = [ plasma ];
services.komorebi = {
enable = true;
config.monitors = [
{
workspaces = [
{
name = "x";
layout = "Nope";
}
];
}
];
};
};
withSource = eval (
{ pkgs, ... }:
{
imports = [ plasma ];
services.komorebi = {
enable = true;
config.resize_delta = 70;
applicationSpecificConfiguration.sources = [
{
owner = "someone";
repo = "komorebi-rules";
rev = "0123456789abcdef0123456789abcdef01234567";
hash = pkgs.lib.fakeHash;
}
];
};
}
);
# the same source and config, with the sources turned off
withSourceOff = eval (
{ pkgs, ... }:
{
imports = [ plasma ];
services.komorebi = {
enable = true;
config.resize_delta = 70;
applicationSpecificConfiguration = {
enable = false;
sources = [
{
owner = "someone";
repo = "komorebi-rules";
rev = "0123456789abcdef0123456789abcdef01234567";
hash = pkgs.lib.fakeHash;
}
];
};
};
}
);
# the sources turned off, and no config: nothing is left to write
onlySourceOff = eval (
{ pkgs, ... }:
{
imports = [ plasma ];
services.komorebi = {
enable = true;
applicationSpecificConfiguration = {
enable = false;
sources = [
{
owner = "someone";
repo = "komorebi-rules";
rev = "0123456789abcdef0123456789abcdef01234567";
hash = pkgs.lib.fakeHash;
}
];
};
};
}
);
bothConfigs = eval (
{ pkgs, ... }:
{
imports = [ plasma ];
services.komorebi = {
enable = true;
configFile = pkgs.writeText "komorebi.json" "{}";
config.resize_delta = 70;
};
}
);
unknownLevel = eval {
imports = [ plasma ];
services.komorebi = {
@@ -196,11 +321,87 @@ let
{
name = "configFile reaches execStart and the unit as --config, after the log level";
ok =
withConfigFile.services.komorebi.execStart
== "${withConfigFile.services.komorebi.package}/bin/komorebi --log-level info --config ${withConfigFile.services.komorebi.configFile}"
lib.hasPrefix "${withConfigFile.services.komorebi.package}/bin/komorebi --log-level info --config /nix/store/" withConfigFile.services.komorebi.execStart
&& (unit withConfigFile).serviceConfig.ExecStart == withConfigFile.services.komorebi.execStart;
got = (unit withConfigFile).serviceConfig.ExecStart;
}
{
name = "with neither a configFile nor a config, there is nothing to write";
ok = enabled.services.komorebi.internal.configAttrs == null;
}
{
name = "config is the komorebi.json the daemon is given, with no null left in it";
ok =
withConfig.services.komorebi.internal.configAttrs.default_workspace_padding == 20
&&
map (w: w.name) (lib.head withConfig.services.komorebi.internal.configAttrs.monitors).workspaces
== [
"web"
"code"
]
&& !(lib.hasInfix "null" (builtins.toJSON withConfig.services.komorebi.internal.configAttrs));
got = withConfig.services.komorebi.internal.configAttrs;
}
{
name = "the keys of the stacks, the float override, monocle and the floating layer are typed options";
ok =
withConfig.services.komorebi.internal.configAttrs.window_container_behaviour == "Append"
&& withConfig.services.komorebi.internal.configAttrs.float_override_placement == "Center"
&& withConfig.services.komorebi.internal.configAttrs.monocle_focus_behaviour == "Cycle"
&&
(lib.head withConfig.services.komorebi.internal.configAttrs.monitors).floating_layer_behaviour
== "Tile"
&&
(lib.elemAt (lib.head withConfig.services.komorebi.internal.configAttrs.monitors).workspaces 1)
.window_container_behaviour_rules."2" == "Append";
got = withConfig.services.komorebi.internal.configAttrs;
}
{
name = "config reaches execStart as a komorebi.json that was checked against the schema";
ok =
lib.hasInfix " --config " withConfig.services.komorebi.execStart
&& lib.hasSuffix "-validated-komorebi.json" withConfig.services.komorebi.execStart
&& (unit withConfig).serviceConfig.ExecStart == withConfig.services.komorebi.execStart;
got = withConfig.services.komorebi.execStart;
}
{
name = "configFile is checked against the schema too";
ok = lib.hasSuffix "-validated-komorebi.json" withConfigFile.services.komorebi.execStart;
got = withConfigFile.services.komorebi.execStart;
}
{
name = "a layout komorebi does not have does not evaluate";
ok = !(evaluates (builtins.deepSeq badLayout.services.komorebi.internal.configAttrs true));
}
{
name = "a source of application specific configuration is the daemon's app_specific_configuration_path";
ok =
lib.hasSuffix "-applications.json" withSource.services.komorebi.internal.configAttrs.app_specific_configuration_path
&& withSource.services.komorebi.internal.configAttrs.resize_delta == 70;
got = withSource.services.komorebi.internal.configAttrs.app_specific_configuration_path;
}
{
name = "with applicationSpecificConfiguration.enable = false, the sources are left out of config";
ok =
withSource.services.komorebi.internal.configAttrs ? app_specific_configuration_path
&& !(withSourceOff.services.komorebi.internal.configAttrs ? app_specific_configuration_path)
&& withSourceOff.services.komorebi.internal.configAttrs.resize_delta == 70;
got = withSourceOff.services.komorebi.internal.configAttrs;
}
{
name = "with the sources turned off and no config, there is nothing to write and no --config";
ok =
onlySourceOff.services.komorebi.internal.configAttrs == null
&& !(lib.hasInfix "--config" onlySourceOff.services.komorebi.execStart);
got = onlySourceOff.services.komorebi.execStart;
}
{
name = "with a configFile, config is ignored, and the module says so";
ok =
lib.any (lib.hasInfix "services.komorebi.config is ignored") bothConfigs.warnings
&& lib.hasSuffix "-validated-komorebi.json" bothConfigs.services.komorebi.execStart;
got = bothConfigs.warnings;
}
{
name = "a log level the daemon does not have does not evaluate";
ok = !(evaluates unknownLevel.services.komorebi.logLevel);
+4
View File
@@ -426,6 +426,10 @@ for args in [
"data-directory",
"configuration",
"generate-static-config",
"static-config-schema",
"application-specific-configuration-schema",
"notification-schema",
"socket-schema",
"session-float-rules",
]:
checks.check(f"komorebic {args}", kde.run(f"komorebic {args}")[0] == 0)
+21 -20
View File
@@ -2,24 +2,25 @@
tier = "fast";
kind = "session";
timeoutMinutes = 10;
# the unit starts the daemon with this file, as `--config`: two named workspaces, and a padding
# that moves the tile of the first window away from the edge of the screen
node =
{ pkgs, ... }:
{
services.komorebi.configFile = pkgs.writeText "komorebi.json" ''
{
"default_workspace_padding": 40,
"default_container_padding": 0,
"monitors": [
{
"workspaces": [
{ "name": "web", "layout": "BSP" },
{ "name": "code", "layout": "Columns" }
]
}
]
}
'';
};
# the module writes this as a komorebi.json, checks it against the schema, and the unit starts
# the daemon with it, as `--config`: two named workspaces, and a padding that moves the tile of
# the first window away from the edge of the screen
node.services.komorebi.config = {
default_workspace_padding = 40;
default_container_padding = 0;
monitors = [
{
workspaces = [
{
name = "web";
layout = "BSP";
}
{
name = "code";
layout = "Columns";
}
];
}
];
};
}
+6 -6
View File
@@ -1,11 +1,11 @@
# The NixOS module runs komorebi in a real Plasma session: nothing in this test starts the daemon.
# What only a real session can tell: that logging in starts the module's user unit through
# `plasma-workspace.target`, that the daemon it runs reaches KWin from there and tiles a window
# opened in the session, that it runs with the module's log level, its `configFile` and the PATH
# of the user's session, that systemd starts it again when it is killed, and that a clean stop is
# not a failure. Once the unit is stopped, the daemon is started with a `komorebi.json` of the
# user's, which it follows when the file changes.
# The options and the unit the module writes are checked without a machine by `nixos-module-eval`
# opened in the session, that it runs with the module's log level, the `komorebi.json` the module
# wrote from its `config`, and the PATH of the user's session, that systemd starts it again when
# it is killed, and that a clean stop is not a failure. Once the unit is stopped, the daemon is
# started with a `komorebi.json` of the user's, which it follows when the file changes. The
# options and the unit the module writes are checked without a machine by `nixos-module-eval`
# (`nix/tests/nixos-module.nix`).
import json
import shlex
@@ -65,7 +65,7 @@ print(f" the unit runs: {' '.join(command)}")
checks.check("the unit runs bin/komorebi", command[0].endswith("/bin/komorebi"))
checks.check("... at the module's log level", command[1:3] == ["--log-level", "debug"])
checks.check(
"... with the module's configFile as its --config",
"... with the komorebi.json the module wrote as its --config",
len(command) == 5 and command[3] == "--config" and command[4].endswith("-komorebi.json"),
)
environment = kde.sh(f"tr '\\0' '\\n' < /proc/{pid}/environ").splitlines()