jjui: Add options to configure settings in Lua including plugins

Options for https://idursun.github.io/jjui/customization/config-lua/.
This commit is contained in:
David Chocholatý
2026-04-12 09:15:06 +02:00
committed by Austin Horstman
parent 0c8ef0f2b9
commit 44111a5c6f
6 changed files with 191 additions and 11 deletions

View File

@@ -0,0 +1,16 @@
{
time = "2026-04-12T11:50:28+00:00";
condition = true;
message = ''
The `programs.jjui` module has been updated to the latest jjui configuration options.
To adhere to the jjui defaults, `configDir` on Darwin now defaults to `~/.config/jjui/` from the previous `~/Library/Application Support/jjui/`.
See https://idursun.github.io/jjui/customization/config-toml/.
New module options are available:
- `configLua` to configure the top-level Lua configuration, and
- `plugins` to define Lua plugins.
Remember to import and set up the defined plugins in `configLua`.
For documentation on Lua configuration, see https://idursun.github.io/jjui/customization/config-lua/.
'';
}

View File

@@ -41,20 +41,107 @@ in
};
};
description = ''
Options to add to the {file}`config.toml` file. See
<https://github.com/idursun/jjui/wiki/Configuration>
Options to add to the {file}`(config.programs.jjui.configDir)/config.toml` file. See
<https://idursun.github.io/jjui/customization/config-toml/>
for options.
'';
};
configLua = mkOption {
type = with lib.types; nullOr (either path lines);
default = null;
example = /* lua */ ''
local foo = require("plugins.foo")
local bar = require("plugins.bar")
function setup(config)
foo.setup(config)
bar.setup("#5B8DEF", config)
config.action("show diff in diffnav", function()
local change_id = context.change_id()
if not change_id or change_id == "" then
flash({ text = "No revision selected", error = true })
return
end
exec_shell(string.format("jj diff -r %q --git --color always | diffnav", change_id))
end, { desc = "show diff in diffnav", key = "ctrl+d", scope = "revisions" })
end
'';
description = ''
The content of the {file}`(config.programs.jjui.configDir)/config.lua` file, set either by specifying a path
to a Lua file or by providing a multi-line Lua string.
See <https://idursun.github.io/jjui/customization/config-lua/> for documentation on Lua support.
Use the option {option}`plugins` to configure Lua plugins imported here.
'';
};
plugins = mkOption {
type =
with lib.types;
attrsOf (oneOf [
path
lines
]);
default = { };
description = ''
Lua plugins, one per attribute.
The <name> attribute will become the plugin name, and the <value> attribute is a path to a Lua file or a multi-line Lua string.
Each attribute will be linked to {file}`(config.programs.jjui.configDir)/plugins/<name>.lua` with <value> content.
See <https://idursun.github.io/jjui/customization/config-lua/>
for documentation on Lua support.
Remember to import the defined plugins in the {option}`configLua` option.
'';
example = lib.literalExpression ''
{
foo = ./foo.lua;
bar = /* lua */ '\'
local M = {}
function M.setup(primary, config)
config.ui = config.ui or {}
config.ui.colors = config.ui.colors or {}
config.ui.colors.title = { fg = primary, bold = true }
end
return M
'\';
}
'';
};
};
config = mkIf cfg.enable {
home = {
packages = mkIf (cfg.package != null) [ cfg.package ];
file."${cfg.configDir}/config.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "jjui-config" cfg.settings;
};
file =
lib.mapAttrs' (name: content: {
name = "${cfg.configDir}/plugins/${name}.lua";
value =
if builtins.isPath content || lib.isStorePath content then
{ source = content; }
else
{ text = content; };
}) cfg.plugins
// {
"${cfg.configDir}/config.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "jjui-config" cfg.settings;
};
"${cfg.configDir}/config.lua" = mkIf (cfg.configLua != null) (
if builtins.isPath cfg.configLua || lib.isStorePath cfg.configLua then
{ source = cfg.configLua; }
else
{ text = cfg.configLua; }
);
};
sessionVariables = {
JJUI_CONFIG_DIR = cfg.configDir;

View File

@@ -0,0 +1,10 @@
local M = {}
function M.setup(primary, config)
config.ui = config.ui or {}
config.ui.colors = config.ui.colors or {}
config.ui.colors.title = { fg = primary, bold = true }
end
return M

View File

@@ -0,0 +1,17 @@
local foo = require("plugins.foo")
local bar = require("plugins.bar")
function setup(config)
foo.setup("#5B8DEF", config)
bar.setup("#5B8DEF", config)
config.action("show diff in diffnav", function()
local change_id = context.change_id()
if not change_id or change_id == "" then
flash({ text = "No revision selected", error = true })
return
end
exec_shell(string.format("jj diff -r %q --git --color always | diffnav", change_id))
end, { desc = "show diff in diffnav", key = "ctrl+d", scope = "revisions" })
end

View File

@@ -1,9 +1,3 @@
{
config,
pkgs,
...
}:
{
config = {
programs.jjui = {
@@ -14,6 +8,40 @@
revset = "ancestors(@ | heads(remote_branches())) ~ empty()";
};
};
configLua = /* lua */ ''
local foo = require("plugins.foo")
local bar = require("plugins.bar")
function setup(config)
foo.setup("#5B8DEF", config)
bar.setup("#5B8DEF", config)
config.action("show diff in diffnav", function()
local change_id = context.change_id()
if not change_id or change_id == "" then
flash({ text = "No revision selected", error = true })
return
end
exec_shell(string.format("jj diff -r %q --git --color always | diffnav", change_id))
end, { desc = "show diff in diffnav", key = "ctrl+d", scope = "revisions" })
end
'';
plugins = {
foo = ./foo.lua;
bar = /* lua */ ''
local M = {}
function M.setup(primary, config)
config.ui = config.ui or {}
config.ui.colors = config.ui.colors or {}
config.ui.colors.title = { fg = primary, bold = true }
end
return M
'';
};
};
nmt.script =
@@ -24,6 +52,18 @@
assertFileContent \
"home-files/${configDir}/config.toml" \
${./example-settings-expected.toml}
assertFileContent \
"home-files/${configDir}/config.lua" \
${./config-expected.lua}
assertFileContent \
"home-files/${configDir}/plugins/foo.lua" \
${./foo.lua}
assertFileContent \
"home-files/${configDir}/plugins/bar.lua" \
${./bar-expected.lua}
'';
};
}

View File

@@ -0,0 +1,10 @@
local M = {}
function M.setup(primary, config)
config.ui = config.ui or {}
config.ui.colors = config.ui.colors or {}
config.ui.colors.selected = { fg = primary, bg = selected_bg, bold = true }
end
return M