Skip to content

Commit 43de56a

Browse files
programs/yazi: add more config options
1 parent e47b244 commit 43de56a

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

modules/collection/programs/yazi.nix

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
pkgs,
55
...
66
}: let
7+
inherit (builtins) isPath;
8+
79
inherit (lib.modules) mkIf;
8-
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
10+
inherit (lib.attrsets) mapAttrs' nameValuePair;
11+
inherit (lib.options) mkOption mkEnableOption mkPackageOption literalExpression;
12+
inherit (lib.types) attrsOf nullOr either path lines package;
913

1014
toml = pkgs.formats.toml {};
1115

@@ -68,21 +72,75 @@ in {
6872
[yazi's theming configuration documentation]: https://yazi-rs.github.io/docs/configuration/theme
6973
'';
7074
};
75+
76+
initLua = mkOption {
77+
type = nullOr (either lines path);
78+
default = null;
79+
example = literalExpression "./init.lua";
80+
description = ''
81+
The `init.lua` file written to {file}`$XDG_CONFIG_HOME/yazi/init.lua`.
82+
Please reference [yazi's plugins documentation] to get a better understanding the the file's usage.
83+
84+
[yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/
85+
'';
86+
};
87+
88+
plugins = mkOption {
89+
type = attrsOf (either path package);
90+
default = {};
91+
example = literalExpression ''
92+
{
93+
foo = ./foo;
94+
git = pkgs.yaziPlugins.git;
95+
};
96+
'';
97+
description = ''
98+
A list of plugins for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/plugins/` folder.
99+
Please reference [yazi's plugins documentation] to get a better understanding of plugins.
100+
101+
[yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/
102+
'';
103+
};
104+
105+
flavors = mkOption {
106+
type = attrsOf (either path package);
107+
default = {};
108+
example = literalExpression ''
109+
{
110+
foo = ./foo;
111+
bar = fetchFromGitHub { ... };
112+
};
113+
'';
114+
description = ''
115+
A list of "flavors", or pre-made themes for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/flavors` folder.
116+
Please reference [yazi's flavors documentation] to get a better understanding of flavors.
117+
118+
[yazi's flavors documentation]: https://yazi-rs.github.io/docs/flavors/overview
119+
'';
120+
};
71121
};
72122

73123
config = mkIf cfg.enable {
74124
packages = mkIf (cfg.package != null) [cfg.package];
75125

76-
xdg.config.files = {
77-
"yazi/yazi.toml" = mkIf (cfg.settings != {}) {
78-
source = toml.generate "yazi-config.toml" cfg.settings;
79-
};
80-
"yazi/keymap.toml" = mkIf (cfg.keymap != {}) {
81-
source = toml.generate "yazi-keymap-config.toml" cfg.keymap;
82-
};
83-
"yazi/theme.toml" = mkIf (cfg.theme != {}) {
84-
source = toml.generate "yazi-theme-config.toml" cfg.theme;
85-
};
86-
};
126+
xdg.config.files =
127+
{
128+
"yazi/yazi.toml" = mkIf (cfg.settings != {}) {
129+
source = toml.generate "yazi-config.toml" cfg.settings;
130+
};
131+
"yazi/keymap.toml" = mkIf (cfg.keymap != {}) {
132+
source = toml.generate "yazi-keymap-config.toml" cfg.keymap;
133+
};
134+
"yazi/theme.toml" = mkIf (cfg.theme != {}) {
135+
source = toml.generate "yazi-theme-config.toml" cfg.theme;
136+
};
137+
"yazi/init.lua" = mkIf (cfg.luaInit != null) (
138+
if isPath cfg.initLua
139+
then {source = cfg.initLua;}
140+
else {text = cfg.initLua;}
141+
);
142+
}
143+
// (mapAttrs' (name: plugin: nameValuePair "yazi/plugins/${name}.yazi" {source = plugin;}) cfg.plugins)
144+
// (mapAttrs' (name: flavor: nameValuePair "yazi/flavors/${name}.yazi" {source = flavor;}) cfg.flavors);
87145
};
88146
}

modules/tests/collection/programs/yazi.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
light = "gruvbox";
2525
};
2626
};
27+
plugins = {inherit (pkgs.yaziPlugins) git;};
28+
flavors = let
29+
yaziFlavors = pkgs.fetchFromGitHub {
30+
owner = "yazi-rs";
31+
repo = "flavors";
32+
rev = "2d73b79da7c1a04420c6c5ef0b0974697f947ef6";
33+
hash = "sha256-+awiEG5ep0/6GaW8YXJ7FP0/xrL4lSrJZgr7qjh8iBc=";
34+
};
35+
in {
36+
dracula = "${yaziFlavors}/dracula.yazi";
37+
};
2738
};
2839
};
2940
};
@@ -39,11 +50,15 @@
3950
yaziConfPath = confDir + "/yazi.toml"
4051
keymapConfPath = confDir + "/keymap.toml"
4152
themeConfPath = confDir + "/theme.toml"
53+
gitPluginDir = confDir + "/plugins/git.yazi"
54+
draculaFlavorDir = confDir + "/flavors/dracula.yazi"
4255
4356
# Checks if the yazi config files exists in the expected place.
4457
machine.succeed("[ -r %s ]" % yaziConfPath)
4558
machine.succeed("[ -r %s ]" % keymapConfPath)
4659
machine.succeed("[ -r %s ]" % themeConfPath)
60+
machine.succeed("[ -d %s ]" % gitPluginDir)
61+
machine.succeed("[ -d %s ]" % draculaFlavorDir)
4762
4863
# Checks if the yazi config files are valid
4964
machine.succeed("su bob -c 'taplo check --schema https://yazi-rs.github.io/schemas/yazi.json %s'" % yaziConfPath)

0 commit comments

Comments
 (0)