2023-08-27 20:47:47 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.yazi;
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
|
2023-09-22 13:00:16 +02:00
|
|
|
bashIntegration = ''
|
2023-08-27 20:47:47 +02:00
|
|
|
function ya() {
|
2024-02-27 00:00:56 +01:00
|
|
|
local tmp="$(mktemp -t "yazi-cwd.XXXXX")"
|
2023-12-16 00:07:57 +01:00
|
|
|
yazi "$@" --cwd-file="$tmp"
|
2023-08-27 20:47:47 +02:00
|
|
|
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
2024-05-27 23:50:57 +02:00
|
|
|
builtin cd -- "$cwd"
|
2023-08-27 20:47:47 +02:00
|
|
|
fi
|
|
|
|
rm -f -- "$tmp"
|
|
|
|
}
|
|
|
|
'';
|
2023-09-22 13:00:16 +02:00
|
|
|
|
|
|
|
fishIntegration = ''
|
|
|
|
function ya
|
|
|
|
set tmp (mktemp -t "yazi-cwd.XXXXX")
|
2023-12-16 00:07:57 +01:00
|
|
|
yazi $argv --cwd-file="$tmp"
|
2023-11-25 09:17:54 +01:00
|
|
|
if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
|
2024-05-27 23:50:57 +02:00
|
|
|
builtin cd -- "$cwd"
|
2023-09-22 13:00:16 +02:00
|
|
|
end
|
|
|
|
rm -f -- "$tmp"
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
|
|
|
nushellIntegration = ''
|
2024-02-27 00:00:56 +01:00
|
|
|
def --env ya [...args] {
|
2024-01-03 20:18:53 +01:00
|
|
|
let tmp = (mktemp -t "yazi-cwd.XXXXX")
|
2024-02-27 00:00:56 +01:00
|
|
|
yazi ...$args --cwd-file $tmp
|
2023-11-25 09:17:54 +01:00
|
|
|
let cwd = (open $tmp)
|
2023-09-22 13:00:16 +02:00
|
|
|
if $cwd != "" and $cwd != $env.PWD {
|
|
|
|
cd $cwd
|
|
|
|
}
|
2024-02-27 00:00:56 +01:00
|
|
|
rm -fp $tmp
|
2023-09-22 13:00:16 +02:00
|
|
|
}
|
|
|
|
'';
|
2023-08-27 20:47:47 +02:00
|
|
|
in {
|
2024-05-29 05:01:52 +02:00
|
|
|
meta.maintainers = with maintainers; [ xyenon ];
|
2023-08-27 20:47:47 +02:00
|
|
|
|
|
|
|
options.programs.yazi = {
|
|
|
|
enable = mkEnableOption "yazi";
|
|
|
|
|
2024-05-29 05:01:52 +02:00
|
|
|
package = mkPackageOption pkgs "yazi" { };
|
2023-08-27 20:47:47 +02:00
|
|
|
|
|
|
|
enableBashIntegration = mkEnableOption "Bash integration";
|
|
|
|
|
|
|
|
enableZshIntegration = mkEnableOption "Zsh integration";
|
|
|
|
|
2023-09-22 13:00:16 +02:00
|
|
|
enableFishIntegration = mkEnableOption "Fish integration";
|
|
|
|
|
|
|
|
enableNushellIntegration = mkEnableOption "Nushell integration";
|
|
|
|
|
2023-08-27 20:47:47 +02:00
|
|
|
keymap = mkOption {
|
|
|
|
type = tomlFormat.type;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
input.keymap = [
|
|
|
|
{ exec = "close"; on = [ "<C-q>" ]; }
|
|
|
|
{ exec = "close --submit"; on = [ "<Enter>" ]; }
|
|
|
|
{ exec = "escape"; on = [ "<Esc>" ]; }
|
|
|
|
{ exec = "backspace"; on = [ "<Backspace>" ]; }
|
|
|
|
];
|
|
|
|
manager.keymap = [
|
|
|
|
{ exec = "escape"; on = [ "<Esc>" ]; }
|
|
|
|
{ exec = "quit"; on = [ "q" ]; }
|
|
|
|
{ exec = "close"; on = [ "<C-q>" ]; }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
|
|
|
{file}`$XDG_CONFIG_HOME/yazi/keymap.toml`.
|
|
|
|
|
2023-11-25 09:17:54 +01:00
|
|
|
See <https://yazi-rs.github.io/docs/configuration/keymap>
|
2023-08-27 20:47:47 +02:00
|
|
|
for the full list of options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = tomlFormat.type;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
log = {
|
|
|
|
enabled = false;
|
|
|
|
};
|
|
|
|
manager = {
|
|
|
|
show_hidden = false;
|
|
|
|
sort_by = "modified";
|
|
|
|
sort_dir_first = true;
|
|
|
|
sort_reverse = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
|
|
|
{file}`$XDG_CONFIG_HOME/yazi/yazi.toml`.
|
|
|
|
|
2023-11-25 09:17:54 +01:00
|
|
|
See <https://yazi-rs.github.io/docs/configuration/yazi>
|
2023-08-27 20:47:47 +02:00
|
|
|
for the full list of options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
theme = mkOption {
|
|
|
|
type = tomlFormat.type;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
filetype = {
|
|
|
|
rules = [
|
|
|
|
{ fg = "#7AD9E5"; mime = "image/*"; }
|
|
|
|
{ fg = "#F3D398"; mime = "video/*"; }
|
|
|
|
{ fg = "#F3D398"; mime = "audio/*"; }
|
|
|
|
{ fg = "#CD9EFC"; mime = "application/x-bzip"; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
|
|
|
{file}`$XDG_CONFIG_HOME/yazi/theme.toml`.
|
|
|
|
|
2023-11-25 09:17:54 +01:00
|
|
|
See <https://yazi-rs.github.io/docs/configuration/theme>
|
2023-08-27 20:47:47 +02:00
|
|
|
for the full list of options
|
|
|
|
'';
|
|
|
|
};
|
2024-05-29 05:01:52 +02:00
|
|
|
|
|
|
|
initLua = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The init.lua for Yazi itself.
|
|
|
|
'';
|
|
|
|
example = literalExpression "./init.lua";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ path package ]);
|
|
|
|
default = { };
|
|
|
|
description = ''
|
2024-06-05 21:24:18 +02:00
|
|
|
Lua plugins.
|
|
|
|
Values should be a package or path containing an `init.lua` file.
|
|
|
|
Will be linked to {file}`$XDG_CONFIG_HOME/yazi/plugins/<name>.yazi`.
|
2024-05-29 05:01:52 +02:00
|
|
|
|
2024-06-03 19:39:00 +02:00
|
|
|
See <https://yazi-rs.github.io/docs/plugins/overview>
|
|
|
|
for documentation.
|
2024-05-29 05:01:52 +02:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
foo = ./foo;
|
|
|
|
bar = pkgs.bar;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
flavors = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ path package ]);
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Pre-made themes.
|
2024-06-06 12:05:28 +02:00
|
|
|
Values should be a package or path containing the required files.
|
2024-06-05 21:24:18 +02:00
|
|
|
Will be linked to {file}`$XDG_CONFIG_HOME/yazi/flavors/<name>.yazi`.
|
2024-05-29 05:01:52 +02:00
|
|
|
|
2024-06-03 19:39:00 +02:00
|
|
|
See <https://yazi-rs.github.io/docs/flavors/overview/> for documentation.
|
2024-05-29 05:01:52 +02:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
foo = ./foo;
|
|
|
|
bar = pkgs.bar;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-08-27 20:47:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2023-09-22 13:00:16 +02:00
|
|
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration;
|
|
|
|
|
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration bashIntegration;
|
|
|
|
|
|
|
|
programs.fish.interactiveShellInit =
|
|
|
|
mkIf cfg.enableFishIntegration fishIntegration;
|
2023-08-27 20:47:47 +02:00
|
|
|
|
2023-09-22 13:00:16 +02:00
|
|
|
programs.nushell.extraConfig =
|
|
|
|
mkIf cfg.enableNushellIntegration nushellIntegration;
|
2023-08-27 20:47:47 +02:00
|
|
|
|
|
|
|
xdg.configFile = {
|
|
|
|
"yazi/keymap.toml" = mkIf (cfg.keymap != { }) {
|
|
|
|
source = tomlFormat.generate "yazi-keymap" cfg.keymap;
|
|
|
|
};
|
|
|
|
"yazi/yazi.toml" = mkIf (cfg.settings != { }) {
|
|
|
|
source = tomlFormat.generate "yazi-settings" cfg.settings;
|
|
|
|
};
|
|
|
|
"yazi/theme.toml" = mkIf (cfg.theme != { }) {
|
|
|
|
source = tomlFormat.generate "yazi-theme" cfg.theme;
|
|
|
|
};
|
2024-05-29 05:01:52 +02:00
|
|
|
"yazi/init.lua" = mkIf (cfg.initLua != null) { source = cfg.initLua; };
|
2024-06-05 21:24:18 +02:00
|
|
|
} // (mapAttrs' (name: value:
|
|
|
|
nameValuePair "yazi/flavors/${name}.yazi" { source = value; })
|
|
|
|
cfg.flavors) // (mapAttrs' (name: value:
|
|
|
|
nameValuePair "yazi/plugins/${name}.yazi" { source = value; })
|
|
|
|
cfg.plugins);
|
|
|
|
|
|
|
|
warnings = filter (s: s != "") (concatLists [
|
|
|
|
(mapAttrsToList (name: value:
|
|
|
|
optionalString (hasSuffix ".yazi" name) ''
|
|
|
|
Flavors like `programs.yazi.flavors."${name}"` should no longer have the suffix ".yazi" in their attribute name.
|
|
|
|
The flavor will be linked to `$XDG_CONFIG_HOME/yazi/flavors/${name}.yazi`.
|
|
|
|
You probably want to rename it to `programs.yazi.flavors."${
|
|
|
|
removeSuffix ".yazi" name
|
|
|
|
}"`.
|
|
|
|
'') cfg.flavors)
|
|
|
|
(mapAttrsToList (name: value:
|
|
|
|
optionalString (hasSuffix ".yazi" name) ''
|
|
|
|
Plugins like `programs.yazi.plugins."${name}"` should no longer have the suffix ".yazi" in their attribute name.
|
|
|
|
The plugin will be linked to `$XDG_CONFIG_HOME/yazi/plugins/${name}.yazi`.
|
|
|
|
You probably want to rename it to `programs.yazi.plugins."${
|
|
|
|
removeSuffix ".yazi" name
|
|
|
|
}"`.
|
|
|
|
'') cfg.plugins)
|
|
|
|
]);
|
|
|
|
|
|
|
|
assertions = let
|
2024-06-06 12:05:28 +02:00
|
|
|
mkAsserts = opt: requiredFiles:
|
2024-06-05 21:24:18 +02:00
|
|
|
mapAttrsToList (name: value:
|
|
|
|
let
|
|
|
|
isDir = pathIsDirectory "${value}";
|
|
|
|
msgNotDir = optionalString (!isDir)
|
|
|
|
"The path or package should be a directory, not a single file.";
|
2024-06-06 12:05:28 +02:00
|
|
|
isFileMissing = file:
|
|
|
|
!(pathExists "${value}/${file}")
|
|
|
|
|| pathIsDirectory "${value}/${file}";
|
|
|
|
missingFiles = filter isFileMissing requiredFiles;
|
|
|
|
msgFilesMissing = optionalString (missingFiles != [ ])
|
|
|
|
"The ${singularOpt} is missing these files: ${
|
|
|
|
toString missingFiles
|
|
|
|
}";
|
2024-06-05 21:24:18 +02:00
|
|
|
singularOpt = removeSuffix "s" opt;
|
|
|
|
in {
|
2024-06-06 12:05:28 +02:00
|
|
|
assertion = isDir && missingFiles == [ ];
|
2024-06-05 21:24:18 +02:00
|
|
|
message = ''
|
|
|
|
Value at `programs.yazi.${opt}.${name}` is not a valid yazi ${singularOpt}.
|
|
|
|
${msgNotDir}
|
2024-06-06 12:05:28 +02:00
|
|
|
${msgFilesMissing}
|
2024-06-05 21:24:18 +02:00
|
|
|
Evaluated value: `${value}`
|
|
|
|
'';
|
|
|
|
}) cfg.${opt};
|
2024-06-06 12:05:28 +02:00
|
|
|
in (mkAsserts "flavors" [
|
|
|
|
"flavor.toml"
|
|
|
|
"tmtheme.xml"
|
|
|
|
"README.md"
|
|
|
|
"preview.png"
|
|
|
|
"LICENSE"
|
|
|
|
"LICENSE-tmtheme"
|
|
|
|
]) ++ (mkAsserts "plugins" [ "init.lua" ]);
|
2023-08-27 20:47:47 +02:00
|
|
|
};
|
|
|
|
}
|