yazi: Ensure plugin suffix .yazi

- Append suffix `.yazi` to symlink targets of yazi plugins, if needed
- Improve some docs, especially links to upstream docs.
- Update tests to make use of this feature.
This commit is contained in:
lordkekz 2024-06-03 19:39:00 +02:00 committed by Robert Helgesson
parent 8be82697f7
commit 5ccc3d6739
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
2 changed files with 27 additions and 9 deletions

View file

@ -144,9 +144,10 @@ in {
type = with types; attrsOf (oneOf [ path package ]);
default = { };
description = ''
Lua plugins.
Lua plugins. Will be linked into {file}`$XDG_CONFIG_HOME/yazi/plugins/`.
See https://yazi-rs.github.io/docs/plugins/overview/ for documentation.
See <https://yazi-rs.github.io/docs/plugins/overview>
for documentation.
'';
example = literalExpression ''
{
@ -162,7 +163,7 @@ in {
description = ''
Pre-made themes.
See https://yazi-rs.github.io/docs/flavors/overview/ for documentation.
See <https://yazi-rs.github.io/docs/flavors/overview/> for documentation.
'';
example = literalExpression ''
{
@ -171,7 +172,6 @@ in {
}
'';
};
};
config = mkIf cfg.enable {
@ -199,9 +199,22 @@ in {
};
"yazi/init.lua" = mkIf (cfg.initLua != null) { source = cfg.initLua; };
} // (mapAttrs'
(name: value: nameValuePair "yazi/plugins/${name}" { source = value; })
cfg.plugins) // (mapAttrs'
(name: value: nameValuePair "yazi/flavors/${name}" { source = value; })
cfg.flavors);
(name: value: nameValuePair "yazi/flavors/${name}" { source = value; })
cfg.flavors) // (let
# Make sure that the directory ends in `.yazi`, to comply with specification.
# `pluginName` is essential, it's needed to apply config in yazi's `init.lua`
ensureSuffix = pluginName:
if lib.hasSuffix ".yazi" pluginName then
"yazi/plugins/${pluginName}"
else
"yazi/plugins/${pluginName}.yazi";
mkPluginLink = pluginName: pluginPackage: {
name = ensureSuffix pluginName;
value.source = pluginPackage;
};
pluginLinks = mapAttrs' mkPluginLink cfg.plugins;
in pluginLinks);
};
}

View file

@ -70,7 +70,10 @@
};
};
initLua = ./init.lua;
plugins = { "test.yazi" = ./plugin; };
plugins = {
"test.yazi" = ./plugin;
"anotherTest" = ./plugin;
};
flavors = { "test.yazi" = ./flavor; };
};
@ -87,6 +90,8 @@
${./init.lua}
assertFileContent home-files/.config/yazi/plugins/test.yazi/init.lua \
${./plugin/init.lua}
assertFileContent home-files/.config/yazi/plugins/anotherTest.yazi/init.lua \
${./plugin/init.lua}
assertFileContent home-files/.config/yazi/flavors/test.yazi/init.lua \
${./flavor/init.lua}
'';