From 04bc391a90f8ae2a953035f33ddebaeccbc0a36b Mon Sep 17 00:00:00 2001 From: XYenon Date: Wed, 29 May 2024 11:01:52 +0800 Subject: [PATCH] yazi: support plugins and flavors --- modules/programs/yazi.nix | 58 ++++++++++++++++++--- tests/modules/programs/yazi/flavor/init.lua | 1 + tests/modules/programs/yazi/init.lua | 3 ++ tests/modules/programs/yazi/plugin/init.lua | 1 + tests/modules/programs/yazi/settings.nix | 9 ++++ 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 tests/modules/programs/yazi/flavor/init.lua create mode 100644 tests/modules/programs/yazi/init.lua create mode 100644 tests/modules/programs/yazi/plugin/init.lua diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 7ae8acd69..11f4e75cf 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -40,17 +40,12 @@ let } ''; in { - meta.maintainers = [ maintainers.xyenon ]; + meta.maintainers = with maintainers; [ xyenon ]; options.programs.yazi = { enable = mkEnableOption "yazi"; - package = mkOption { - type = types.package; - default = pkgs.yazi; - defaultText = literalExpression "pkgs.yazi"; - description = "Yazi package to install."; - }; + package = mkPackageOption pkgs "yazi" { }; enableBashIntegration = mkEnableOption "Bash integration"; @@ -135,6 +130,48 @@ in { for the full list of options ''; }; + + initLua = mkOption { + type = with types; nullOr path; + default = null; + description = '' + The init.lua for Yazi itself. + ''; + example = literalExpression "./init.lua"; + }; + + plugins = mkOption { + type = with types; attrsOf (oneOf [ path package ]); + default = { }; + description = '' + Lua plugins. + + See https://yazi-rs.github.io/docs/plugins/overview/ for documentation. + ''; + example = literalExpression '' + { + foo = ./foo; + bar = pkgs.bar; + } + ''; + }; + + flavors = mkOption { + type = with types; attrsOf (oneOf [ path package ]); + default = { }; + description = '' + Pre-made themes. + + See https://yazi-rs.github.io/docs/flavors/overview/ for documentation. + ''; + example = literalExpression '' + { + foo = ./foo; + bar = pkgs.bar; + } + ''; + }; + }; config = mkIf cfg.enable { @@ -160,6 +197,11 @@ in { "yazi/theme.toml" = mkIf (cfg.theme != { }) { source = tomlFormat.generate "yazi-theme" cfg.theme; }; - }; + "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); }; } diff --git a/tests/modules/programs/yazi/flavor/init.lua b/tests/modules/programs/yazi/flavor/init.lua new file mode 100644 index 000000000..8d06fa7a9 --- /dev/null +++ b/tests/modules/programs/yazi/flavor/init.lua @@ -0,0 +1 @@ +-- This is a flavor. diff --git a/tests/modules/programs/yazi/init.lua b/tests/modules/programs/yazi/init.lua new file mode 100644 index 000000000..a22493df7 --- /dev/null +++ b/tests/modules/programs/yazi/init.lua @@ -0,0 +1,3 @@ +require("zoxide"):setup { + update_db = true, +} diff --git a/tests/modules/programs/yazi/plugin/init.lua b/tests/modules/programs/yazi/plugin/init.lua new file mode 100644 index 000000000..a9286c3d6 --- /dev/null +++ b/tests/modules/programs/yazi/plugin/init.lua @@ -0,0 +1 @@ +-- This is a plugin. diff --git a/tests/modules/programs/yazi/settings.nix b/tests/modules/programs/yazi/settings.nix index 5a540cafb..4655ae8b3 100644 --- a/tests/modules/programs/yazi/settings.nix +++ b/tests/modules/programs/yazi/settings.nix @@ -69,6 +69,9 @@ ]; }; }; + initLua = ./init.lua; + plugins = { "test.yazi" = ./plugin; }; + flavors = { "test.yazi" = ./flavor; }; }; test.stubs.yazi = { }; @@ -80,5 +83,11 @@ ${./settings-expected.toml} assertFileContent home-files/.config/yazi/theme.toml \ ${./theme-expected.toml} + assertFileContent home-files/.config/yazi/init.lua \ + ${./init.lua} + assertFileContent home-files/.config/yazi/plugins/test.yazi/init.lua \ + ${./plugin/init.lua} + assertFileContent home-files/.config/yazi/flavors/test.yazi/init.lua \ + ${./flavor/init.lua} ''; }