mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 07:08:48 +01:00
build(nix): add generated module opts and validation
This commit adds NixOS module option generation for komorebi and komorebi-bar configurations, along with a nix and JSONSchema validation test harness that runs as part of `nix flake check`. `schemars-nixgen` (same as `schemars-docgen`, not sure if I'm gonna release this...) generates strongly-typed Nix option definitions from the generated JSONSchema files, allowing users to write type-checked Nix configurations that map directly to the config files. This will eventually be plugged into a nix-darwin module which I have yet to start writing.
This commit is contained in:
1 parent
6c575126ad
commit
23aca28267
8 files changed
+2782
-1
No files matched your search
@@ -18,7 +18,7 @@
|
||||
"layout": {
|
||||
"enable": true
|
||||
},
|
||||
"focused_window": {
|
||||
"focused_container": {
|
||||
"enable": true,
|
||||
"show_icon": true
|
||||
}
|
||||
|
||||
@@ -165,6 +165,8 @@
|
||||
};
|
||||
|
||||
komorebi-workspace-nextest = build.craneLib.cargoNextest build.individualCrateArgs;
|
||||
|
||||
nix-options-validation = import ./nix/tests { inherit pkgs; };
|
||||
};
|
||||
|
||||
packages = {
|
||||
|
||||
@@ -62,6 +62,12 @@ schemagen:
|
||||
cp schema.json komorebi-schema/komorebi.{{ version }}.schema.json
|
||||
cp schema.bar.json komorebi-schema/komorebi.bar.{{ version }}.schema.json
|
||||
|
||||
nixgen:
|
||||
schemars-nixgen schema.json -o nix/komorebi-options.nix --name komorebi --description "komorebi for Mac configuration"
|
||||
schemars-nixgen schema.bar.json -o nix/komorebi-bar-options.nix --name komorebi-bar --description "komorebi for Mac bar configuration"
|
||||
nix fmt nix/
|
||||
nix build -f nix/tests/default.nix
|
||||
|
||||
schemapub:
|
||||
wrangler pages deploy --project-name komorebi-for-mac --branch main ./komorebi-schema
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,74 @@
|
||||
# E2E test harness for validating generated Nix options
|
||||
# Run with: nix build -f nix/tests/default.nix
|
||||
# Or via flake: nix flake check (runs as part of checks)
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
|
||||
# Recursively filter out null values and empty attrs from a config
|
||||
# This is needed because the Nix module system uses null for unset optional fields,
|
||||
# but the JSON schema expects those fields to be absent entirely
|
||||
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
|
||||
let
|
||||
filtered = lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value);
|
||||
in
|
||||
filtered
|
||||
else
|
||||
value;
|
||||
|
||||
# Helper to evaluate a config module and extract the config value
|
||||
evalConfig =
|
||||
optionsModule: configModule: configPath:
|
||||
let
|
||||
evaluated = lib.evalModules {
|
||||
modules = [
|
||||
optionsModule
|
||||
configModule
|
||||
];
|
||||
};
|
||||
rawConfig = lib.getAttrFromPath configPath evaluated.config;
|
||||
in
|
||||
filterNulls rawConfig;
|
||||
|
||||
komorebiOptions = import ../komorebi-options.nix;
|
||||
komorebiBarOptions = import ../komorebi-bar-options.nix;
|
||||
|
||||
komorebiExample = import ./komorebi-example.nix;
|
||||
komorebiBarExample = import ./komorebi-bar-example.nix;
|
||||
|
||||
configs = {
|
||||
komorebi-example = evalConfig komorebiOptions komorebiExample [ "komorebi" ];
|
||||
komorebi-bar-example = evalConfig komorebiBarOptions komorebiBarExample [ "komorebi-bar" ];
|
||||
};
|
||||
|
||||
komorebiJson = pkgs.writeText "komorebi-example.json" (builtins.toJSON configs.komorebi-example);
|
||||
komorebiBarJson = pkgs.writeText "komorebi-bar-example.json" (
|
||||
builtins.toJSON configs.komorebi-bar-example
|
||||
);
|
||||
|
||||
schemaPath = ../../schema.json;
|
||||
barSchemaPath = ../../schema.bar.json;
|
||||
|
||||
in
|
||||
pkgs.runCommand "nix-options-validation"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.check-jsonschema ];
|
||||
}
|
||||
''
|
||||
echo "Validating komorebi config against schema..."
|
||||
check-jsonschema --schemafile ${schemaPath} ${komorebiJson}
|
||||
|
||||
echo "Validating komorebi-bar config against schema..."
|
||||
check-jsonschema --schemafile ${barSchemaPath} ${komorebiBarJson}
|
||||
|
||||
echo "All validations passed!"
|
||||
touch $out
|
||||
''
|
||||
@@ -0,0 +1,71 @@
|
||||
# Nix equivalent of docs/komorebi.bar.example.json
|
||||
# This tests that users can write the exact same config in Nix
|
||||
{ ... }:
|
||||
{
|
||||
komorebi-bar = {
|
||||
monitor = 0;
|
||||
font_family = "JetBrainsMono Nerd Font";
|
||||
height = 30.0;
|
||||
|
||||
theme = {
|
||||
palette = "Base16";
|
||||
name = "Ashes";
|
||||
accent = "Base0D";
|
||||
};
|
||||
|
||||
left_widgets = [
|
||||
{
|
||||
Komorebi = {
|
||||
workspaces = {
|
||||
enable = true;
|
||||
hide_empty_workspaces = false;
|
||||
};
|
||||
layout = {
|
||||
enable = true;
|
||||
};
|
||||
focused_container = {
|
||||
enable = true;
|
||||
show_icon = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
right_widgets = [
|
||||
{
|
||||
Update = {
|
||||
enable = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
Storage = {
|
||||
enable = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
Memory = {
|
||||
enable = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
Network = {
|
||||
enable = true;
|
||||
show_activity = true;
|
||||
show_total_activity = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
Date = {
|
||||
enable = true;
|
||||
format = "DayDateMonthYear";
|
||||
};
|
||||
}
|
||||
{
|
||||
Time = {
|
||||
enable = true;
|
||||
format = "TwentyFourHour";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
# 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;
|
||||
border = true;
|
||||
border_width = 6;
|
||||
border_offset = 5;
|
||||
floating_window_aspect_ratio = "Widescreen";
|
||||
floating_layer_behaviour = "Float";
|
||||
resize_delta = 100;
|
||||
ignore_rules = [ ];
|
||||
floating_applications = [ ];
|
||||
manage_rules = [ ];
|
||||
monitors = [
|
||||
{
|
||||
workspaces = [
|
||||
{
|
||||
name = "I";
|
||||
layout = "BSP";
|
||||
initial_workspace_rules = [ ];
|
||||
}
|
||||
{
|
||||
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";
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user