Merge pull request #295846 from linsui/yazi

nixos/yazi: support plugins and flavors
This commit is contained in:
Aleksana 2024-05-18 12:44:27 +08:00 committed by GitHub
commit 419fffedfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 95 additions and 15 deletions

View File

@ -5,7 +5,7 @@ let
settingsFormat = pkgs.formats.toml { }; settingsFormat = pkgs.formats.toml { };
names = [ "yazi" "theme" "keymap" ]; files = [ "yazi" "theme" "keymap" ];
in in
{ {
options.programs.yazi = { options.programs.yazi = {
@ -15,7 +15,7 @@ in
settings = lib.mkOption { settings = lib.mkOption {
type = with lib.types; submodule { type = with lib.types; submodule {
options = lib.listToAttrs (map options = (lib.listToAttrs (map
(name: lib.nameValuePair name (lib.mkOption { (name: lib.nameValuePair name (lib.mkOption {
inherit (settingsFormat) type; inherit (settingsFormat) type;
default = { }; default = { };
@ -25,26 +25,65 @@ in
See https://yazi-rs.github.io/docs/configuration/${name}/ for documentation. See https://yazi-rs.github.io/docs/configuration/${name}/ for documentation.
''; '';
})) }))
names); files));
}; };
default = { }; default = { };
description = '' description = ''
Configuration included in `$YAZI_CONFIG_HOME`. Configuration included in `$YAZI_CONFIG_HOME`.
''; '';
}; };
initLua = lib.mkOption {
type = with lib.types; nullOr path;
default = null;
description = ''
The init.lua for Yazi itself.
'';
example = lib.literalExpression "./init.lua";
};
plugins = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ path package ]);
default = { };
description = ''
Lua plugins.
See https://yazi-rs.github.io/docs/plugins/overview/ for documentation.
'';
example = lib.literalExpression ''
{
foo = ./foo;
bar = pkgs.bar;
}
'';
};
flavors = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ path package ]);
default = { };
description = ''
Pre-made themes.
See https://yazi-rs.github.io/docs/flavors/overview/ for documentation.
'';
example = lib.literalExpression ''
{
foo = ./foo;
bar = pkgs.bar;
}
'';
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment = { environment.systemPackages = [
systemPackages = [ cfg.package ]; (cfg.package.override {
variables.YAZI_CONFIG_HOME = "/etc/yazi/"; inherit (cfg) settings initLua plugins flavors;
etc = lib.attrsets.mergeAttrsList (map })
(name: lib.optionalAttrs (cfg.settings.${name} != { }) { ];
"yazi/${name}.toml".source = settingsFormat.generate "${name}.toml" cfg.settings.${name};
})
names);
};
}; };
meta = { meta = {
maintainers = with lib.maintainers; [ linsui ]; maintainers = with lib.maintainers; [ linsui ];
}; };

View File

@ -44,7 +44,7 @@ rustPlatform.buildRustPackage rec {
description = "Blazing fast terminal file manager written in Rust, based on async I/O"; description = "Blazing fast terminal file manager written in Rust, based on async I/O";
homepage = "https://github.com/sxyazi/yazi"; homepage = "https://github.com/sxyazi/yazi";
license = lib.licenses.mit; license = lib.licenses.mit;
maintainers = with lib.maintainers; [ xyenon matthiasbeyer ]; maintainers = with lib.maintainers; [ xyenon matthiasbeyer linsui ];
mainProgram = "yazi"; mainProgram = "yazi";
}; };
} }

View File

@ -3,6 +3,7 @@
, makeWrapper , makeWrapper
, yazi-unwrapped , yazi-unwrapped
, withRuntimeDeps ? true
, withFile ? true , withFile ? true
, file , file
, withJq ? true , withJq ? true
@ -21,10 +22,16 @@
, fzf , fzf
, withZoxide ? true , withZoxide ? true
, zoxide , zoxide
, settings ? { }
, formats
, plugins ? { }
, flavors ? { }
, initLua ? null
}: }:
let let
runtimePaths = with lib; [ ] runtimePaths = with lib;
[ ]
++ optional withFile file ++ optional withFile file
++ optional withJq jq ++ optional withJq jq
++ optional withPoppler poppler_utils ++ optional withPoppler poppler_utils
@ -34,7 +41,40 @@ let
++ optional withRipgrep ripgrep ++ optional withRipgrep ripgrep
++ optional withFzf fzf ++ optional withFzf fzf
++ optional withZoxide zoxide; ++ optional withZoxide zoxide;
settingsFormat = formats.toml { };
files = [ "yazi" "theme" "keymap" ];
configHome = if (settings == { } && initLua == null && plugins == { } && flavors == { }) then null else
runCommand "YAZI_CONFIG_HOME" { } ''
mkdir -p $out
${lib.concatMapStringsSep
"\n"
(name: lib.optionalString (settings ? ${name} && settings.${name} != { }) ''
ln -s ${settingsFormat.generate "${name}.toml" settings.${name}} $out/${name}.toml
'')
files}
mkdir $out/plugins
${lib.optionalString (plugins != { }) ''
${lib.concatMapStringsSep
"\n"
(lib.mapAttrsToList (name: value: "ln -s ${value} $out/plugins/${name}") plugins)}
''}
mkdir $out/flavors
${lib.optionalString (flavors != { }) ''
${lib.concatMapStringsSep
"\n"
(lib.mapAttrsToList (name: value: "ln -s ${value} $out/flavors/${name}") flavors)}
''}
${lib.optionalString (initLua != null) "ln -s ${initLua} $out/init.lua"}
'';
in in
if (!withRuntimeDeps && configHome == null) then yazi-unwrapped else
runCommand yazi-unwrapped.name runCommand yazi-unwrapped.name
{ {
inherit (yazi-unwrapped) pname version meta; inherit (yazi-unwrapped) pname version meta;
@ -44,5 +84,6 @@ runCommand yazi-unwrapped.name
mkdir -p $out/bin mkdir -p $out/bin
ln -s ${yazi-unwrapped}/share $out/share ln -s ${yazi-unwrapped}/share $out/share
makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \ makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \
--prefix PATH : "${lib.makeBinPath runtimePaths}" ${lib.optionalString withRuntimeDeps "--prefix PATH : \"${lib.makeBinPath runtimePaths}\""} \
${lib.optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"}
'' ''