mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
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:
committed by
Austin Horstman
parent
0c8ef0f2b9
commit
44111a5c6f
16
modules/misc/news/2026/04/2026-04-12_13-50-28.nix
Normal file
16
modules/misc/news/2026/04/2026-04-12_13-50-28.nix
Normal 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/.
|
||||
'';
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
10
tests/modules/programs/jjui/bar-expected.lua
Normal file
10
tests/modules/programs/jjui/bar-expected.lua
Normal 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
|
||||
17
tests/modules/programs/jjui/config-expected.lua
Normal file
17
tests/modules/programs/jjui/config-expected.lua
Normal 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
|
||||
@@ -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}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
||||
10
tests/modules/programs/jjui/foo.lua
Normal file
10
tests/modules/programs/jjui/foo.lua
Normal 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
|
||||
Reference in New Issue
Block a user