Skip to content

Commit 9bacfa3

Browse files
authored
Merge pull request #137 from rice-cracker-dev/programs-yazi
2 parents 1ed95e0 + 7e647cd commit 9bacfa3

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}: let
7+
inherit (lib.modules) mkIf;
8+
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
9+
10+
toml = pkgs.formats.toml {};
11+
12+
cfg = config.rum.programs.yazi;
13+
in {
14+
options.rum.programs.yazi = {
15+
enable = mkEnableOption "yazi file manager";
16+
17+
package = mkPackageOption pkgs "yazi" {nullable = true;};
18+
19+
settings = mkOption {
20+
inherit (toml) type;
21+
default = {};
22+
example = {
23+
mgr = {
24+
show_hidden = true;
25+
};
26+
};
27+
description = ''
28+
The configurations converted to TOML and written to {file}`$XDG_CONFIG_HOME/yazi/yazi.toml`.
29+
Please reference [yazi's configuration documentation] for configuration options.
30+
31+
[yazi's configuration documentation]: https://yazi-rs.github.io/docs/configuration/yazi
32+
'';
33+
};
34+
35+
keymap = mkOption {
36+
inherit (toml) type;
37+
default = {};
38+
example = {
39+
mgr.prepend_keymap = [
40+
{
41+
on = "<C-a>";
42+
run = "my-cmd1";
43+
desc = "Single command with `Ctrl + a`";
44+
}
45+
];
46+
};
47+
description = ''
48+
The keymap configurations converted to TOML and written to {file}`$XDG_CONFIG_HOME/yazi/keymap.toml`.
49+
Please reference [yazi's keymap configuration documentation] for configuration options.
50+
51+
[yazi's keymap configuration documentation]: https://yazi-rs.github.io/docs/configuration/keymap
52+
'';
53+
};
54+
55+
theme = mkOption {
56+
inherit (toml) type;
57+
default = {};
58+
example = {
59+
flavor = {
60+
dark = "dracula";
61+
light = "gruvbox";
62+
};
63+
};
64+
description = ''
65+
The keymap configurations converted to TOML and written to {file}`$XDG_CONFIG_HOME/yazi/theme.toml`.
66+
Please reference [yazi's theming configuration documentation] for configuration options.
67+
68+
[yazi's theming configuration documentation]: https://yazi-rs.github.io/docs/configuration/theme
69+
'';
70+
};
71+
};
72+
73+
config = mkIf cfg.enable {
74+
packages = mkIf (cfg.package != null) [cfg.package];
75+
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+
};
87+
};
88+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{pkgs, ...}: {
2+
name = "programs-yazi";
3+
nodes.machine = {
4+
environment.systemPackages = [pkgs.taplo];
5+
6+
hjem.users.bob.rum = {
7+
programs.yazi = {
8+
enable = true;
9+
settings = {
10+
mgr.show_hidden = true;
11+
};
12+
keymap = {
13+
mgr.prepend_keymap = [
14+
{
15+
on = "<C-a>";
16+
run = "my-cmd1";
17+
desc = "Single command with `Ctrl + a`";
18+
}
19+
];
20+
};
21+
theme = {
22+
flavor = {
23+
dark = "dracula";
24+
light = "gruvbox";
25+
};
26+
};
27+
};
28+
};
29+
};
30+
31+
testScript =
32+
#python
33+
''
34+
# Waiting for our user to load.
35+
machine.succeed("loginctl enable-linger bob")
36+
machine.wait_for_unit("default.target")
37+
38+
confDir = "/home/bob/.config/yazi"
39+
yaziConfPath = confDir + "/yazi.toml"
40+
keymapConfPath = confDir + "/keymap.toml"
41+
themeConfPath = confDir + "/theme.toml"
42+
43+
# Checks if the yazi config files exists in the expected place.
44+
machine.succeed("[ -r %s ]" % yaziConfPath)
45+
machine.succeed("[ -r %s ]" % keymapConfPath)
46+
machine.succeed("[ -r %s ]" % themeConfPath)
47+
48+
# Checks if the yazi config files are valid
49+
machine.succeed("su bob -c 'taplo check --schema https://yazi-rs.github.io/schemas/yazi.json %s'" % yaziConfPath)
50+
machine.succeed("su bob -c 'taplo check --schema https://yazi-rs.github.io/schemas/keymap.json %s'" % keymapConfPath)
51+
machine.succeed("su bob -c 'taplo check --schema https://yazi-rs.github.io/schemas/theme.json %s'" % themeConfPath)
52+
'';
53+
}

0 commit comments

Comments
 (0)