From 5ccc3d6739b5e694841ced27cb5c06b50b163695 Mon Sep 17 00:00:00 2001 From: lordkekz Date: Mon, 3 Jun 2024 19:39:00 +0200 Subject: [PATCH] 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. --- modules/programs/yazi.nix | 29 +++++++++++++++++------- tests/modules/programs/yazi/settings.nix | 7 +++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 11f4e75c..f96a9bdf 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -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 + 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 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); }; } diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index 4655ae8b..33b99c2c 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -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} '';