mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
This commit adds a nix-darwin module for komorebi and komorebi-bar, exposed via `darwinModules.default` and `darwinModules.komorebi`. The module provides the following options: * `services.komorebi.enable`: enables the komorebi launchd agent * `services.komorebi.config`: typed Nix configuration (defaults to example config) * `services.komorebi.configFile`: path to a JSON config file (validated against schema) * `services.komorebi.logLevel`: log verbosity level * `services.komorebi.applicationSpecificConfiguration`: fetches app-specific configs from remote GitHub repositories at pinned revisions * `services.komorebi-bar.enable`: enables komorebi-bar launchd agent(s) * `services.komorebi-bar.bars.<name>`: named bar instances, one per monitor * `services.komorebi-bar.bars.<name>.config`: typed Nix configuration per bar * `services.komorebi-bar.bars.<name>.configFile`: path to a JSON config file per bar The applicationSpecificConfiguration option supports multiple sources, allowing users to combine the upstream default from LGUG2Z/komorebi-application-specific-configuration with their own personal overrides from other repositories. When configFile is specified, the JSON file is validated against the flake's version of the schema before being passed to the binary. A new flake check, `darwin-module-validation`, validates the module options and exercises the configFile validation against the example JSON files loaded into `komorebic` for the `quickstart` cmd.
74 lines
2.2 KiB
Nix
74 lines
2.2 KiB
Nix
# 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;
|
|
|
|
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
|
|
''
|