Skip to content

Commit 3dcef0f

Browse files
programs/yazi: add more config options
1 parent 9bacfa3 commit 3dcef0f

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

modules/collection/programs/yazi.nix

Lines changed: 67 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,72 @@ 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 for Yazi.
82+
'';
83+
};
84+
85+
plugins = mkOption {
86+
type = attrsOf (either path package);
87+
default = {};
88+
example = literalExpression ''
89+
{
90+
foo = ./foo;
91+
git = pkgs.yaziPlugins.git;
92+
};
93+
'';
94+
description = ''
95+
A list of plugins for Yazi, which would be placed in the {file}`$XDG_CONFIG_HOME/yazi/plugins/` folder.
96+
Please reference [yazi's plugins documentation] to get a better understanding of plugins.
97+
98+
[yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/
99+
'';
100+
};
101+
102+
flavors = mkOption {
103+
type = attrsOf (either path package);
104+
default = {};
105+
example = literalExpression ''
106+
{
107+
foo = ./foo;
108+
git = fetchFromGitHub { ... };
109+
};
110+
'';
111+
description = ''
112+
A list of "flavors", or pre-made themes for Yazi, which would be placed in the {file}`$XDG_CONFIG_HOME/yazi/flavors` folder.
113+
Please reference [yazi's flavors documentation] to get a better understanding of flavors.
114+
115+
[yazi's flavors documentation]: https://yazi-rs.github.io/docs/flavors/overview
116+
'';
117+
};
71118
};
72119

73120
config = mkIf cfg.enable {
74121
packages = mkIf (cfg.package != null) [cfg.package];
75122

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

modules/tests/collection/programs/yazi.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
light = "gruvbox";
2525
};
2626
};
27+
plugins = {inherit (pkgs.yaziPlugins) git;};
2728
};
2829
};
2930
};
@@ -39,11 +40,13 @@
3940
yaziConfPath = confDir + "/yazi.toml"
4041
keymapConfPath = confDir + "/keymap.toml"
4142
themeConfPath = confDir + "/theme.toml"
43+
pluginsDir = confDir + "/plugins/"
4244
4345
# Checks if the yazi config files exists in the expected place.
4446
machine.succeed("[ -r %s ]" % yaziConfPath)
4547
machine.succeed("[ -r %s ]" % keymapConfPath)
4648
machine.succeed("[ -r %s ]" % themeConfPath)
49+
machine.succeed("[ -d %s ]" % pluginsDir)
4750
4851
# Checks if the yazi config files are valid
4952
machine.succeed("su bob -c 'taplo check --schema https://yazi-rs.github.io/schemas/yazi.json %s'" % yaziConfPath)

0 commit comments

Comments
 (0)