diff --git a/modules/collection/programs/yazi.nix b/modules/collection/programs/yazi.nix index d2b5d2ac..c7f3d14f 100644 --- a/modules/collection/programs/yazi.nix +++ b/modules/collection/programs/yazi.nix @@ -4,8 +4,12 @@ pkgs, ... }: let + inherit (builtins) isPath; + inherit (lib.modules) mkIf; - inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.attrsets) mapAttrs' nameValuePair; + inherit (lib.options) mkOption mkEnableOption mkPackageOption literalExpression; + inherit (lib.types) attrsOf nullOr either path lines package; toml = pkgs.formats.toml {}; @@ -68,21 +72,75 @@ in { [yazi's theming configuration documentation]: https://yazi-rs.github.io/docs/configuration/theme ''; }; + + initLua = mkOption { + type = nullOr (either lines path); + default = null; + example = literalExpression "./init.lua"; + description = '' + The `init.lua` file written to {file}`$XDG_CONFIG_HOME/yazi/init.lua`. + Please reference [yazi's plugins documentation] to get a better understanding the the file's usage. + + [yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/ + ''; + }; + + plugins = mkOption { + type = attrsOf (either path package); + default = {}; + example = literalExpression '' + { + foo = ./foo; + git = pkgs.yaziPlugins.git; + }; + ''; + description = '' + A list of plugins for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/plugins/` folder. + Please reference [yazi's plugins documentation] to get a better understanding of plugins. + + [yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/ + ''; + }; + + flavors = mkOption { + type = attrsOf (either path package); + default = {}; + example = literalExpression '' + { + foo = ./foo; + bar = fetchFromGitHub { ... }; + }; + ''; + description = '' + A list of "flavors", or pre-made themes for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/flavors` folder. + Please reference [yazi's flavors documentation] to get a better understanding of flavors. + + [yazi's flavors documentation]: https://yazi-rs.github.io/docs/flavors/overview + ''; + }; }; config = mkIf cfg.enable { packages = mkIf (cfg.package != null) [cfg.package]; - xdg.config.files = { - "yazi/yazi.toml" = mkIf (cfg.settings != {}) { - source = toml.generate "yazi-config.toml" cfg.settings; - }; - "yazi/keymap.toml" = mkIf (cfg.keymap != {}) { - source = toml.generate "yazi-keymap-config.toml" cfg.keymap; - }; - "yazi/theme.toml" = mkIf (cfg.theme != {}) { - source = toml.generate "yazi-theme-config.toml" cfg.theme; - }; - }; + xdg.config.files = + { + "yazi/yazi.toml" = mkIf (cfg.settings != {}) { + source = toml.generate "yazi-config.toml" cfg.settings; + }; + "yazi/keymap.toml" = mkIf (cfg.keymap != {}) { + source = toml.generate "yazi-keymap-config.toml" cfg.keymap; + }; + "yazi/theme.toml" = mkIf (cfg.theme != {}) { + source = toml.generate "yazi-theme-config.toml" cfg.theme; + }; + "yazi/init.lua" = mkIf (cfg.initLua != null) ( + if isPath cfg.initLua + then {source = cfg.initLua;} + else {text = cfg.initLua;} + ); + } + // (mapAttrs' (name: plugin: nameValuePair "yazi/plugins/${name}.yazi" {source = plugin;}) cfg.plugins) + // (mapAttrs' (name: flavor: nameValuePair "yazi/flavors/${name}.yazi" {source = flavor;}) cfg.flavors); }; } diff --git a/modules/tests/collection/programs/yazi.nix b/modules/tests/collection/programs/yazi.nix index b5662794..1cc5b1f2 100644 --- a/modules/tests/collection/programs/yazi.nix +++ b/modules/tests/collection/programs/yazi.nix @@ -24,6 +24,17 @@ light = "gruvbox"; }; }; + plugins = {inherit (pkgs.yaziPlugins) git;}; + flavors = let + yaziFlavors = pkgs.fetchFromGitHub { + owner = "yazi-rs"; + repo = "flavors"; + rev = "2d73b79da7c1a04420c6c5ef0b0974697f947ef6"; + hash = "sha256-+awiEG5ep0/6GaW8YXJ7FP0/xrL4lSrJZgr7qjh8iBc="; + }; + in { + dracula = "${yaziFlavors}/dracula.yazi"; + }; }; }; }; @@ -46,11 +57,15 @@ yaziConfPath = confDir + "/yazi.toml" keymapConfPath = confDir + "/keymap.toml" themeConfPath = confDir + "/theme.toml" + gitPluginDir = confDir + "/plugins/git.yazi" + draculaFlavorDir = confDir + "/flavors/dracula.yazi" # Checks if the yazi config files exists in the expected place. machine.succeed("[ -r %s ]" % yaziConfPath) machine.succeed("[ -r %s ]" % keymapConfPath) machine.succeed("[ -r %s ]" % themeConfPath) + machine.succeed("[ -d %s ]" % gitPluginDir) + machine.succeed("[ -d %s ]" % draculaFlavorDir) # Checks if the yazi config files are valid machine.succeed("su bob -c 'taplo check --schema file://${schemaSrc}/schemas/yazi.json %s'" % yaziConfPath)