mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-03 21:54:27 +01:00
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:
1 parent
ed34286bca
commit
3a3a0f8f24
29 files changed
+2754
-49
No files matched your search
@@ -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
|
||||
''
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user