Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 70 additions & 12 deletions modules/collection/programs/yazi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down Expand Up @@ -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);
};
}
15 changes: 15 additions & 0 deletions modules/tests/collection/programs/yazi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};
};
};
Expand All @@ -39,11 +50,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 https://yazi-rs.github.io/schemas/yazi.json %s'" % yaziConfPath)
Expand Down