Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #295846 from linsui/yazi

nixos/yazi: support plugins and flavors

authored by Aleksana and committed by GitHub 419fffed 951f6c89

+95 -15
+51 -12
nixos/modules/programs/yazi.nix
··· 5 5 6 6 settingsFormat = pkgs.formats.toml { }; 7 7 8 - names = [ "yazi" "theme" "keymap" ]; 8 + files = [ "yazi" "theme" "keymap" ]; 9 9 in 10 10 { 11 11 options.programs.yazi = { ··· 15 15 16 16 settings = lib.mkOption { 17 17 type = with lib.types; submodule { 18 - options = lib.listToAttrs (map 18 + options = (lib.listToAttrs (map 19 19 (name: lib.nameValuePair name (lib.mkOption { 20 20 inherit (settingsFormat) type; 21 21 default = { }; ··· 25 25 See https://yazi-rs.github.io/docs/configuration/${name}/ for documentation. 26 26 ''; 27 27 })) 28 - names); 28 + files)); 29 29 }; 30 30 default = { }; 31 31 description = '' 32 32 Configuration included in `$YAZI_CONFIG_HOME`. 33 33 ''; 34 34 }; 35 + 36 + initLua = lib.mkOption { 37 + type = with lib.types; nullOr path; 38 + default = null; 39 + description = '' 40 + The init.lua for Yazi itself. 41 + ''; 42 + example = lib.literalExpression "./init.lua"; 43 + }; 44 + 45 + plugins = lib.mkOption { 46 + type = with lib.types; attrsOf (oneOf [ path package ]); 47 + default = { }; 48 + description = '' 49 + Lua plugins. 50 + 51 + See https://yazi-rs.github.io/docs/plugins/overview/ for documentation. 52 + ''; 53 + example = lib.literalExpression '' 54 + { 55 + foo = ./foo; 56 + bar = pkgs.bar; 57 + } 58 + ''; 59 + }; 60 + 61 + flavors = lib.mkOption { 62 + type = with lib.types; attrsOf (oneOf [ path package ]); 63 + default = { }; 64 + description = '' 65 + Pre-made themes. 66 + 67 + See https://yazi-rs.github.io/docs/flavors/overview/ for documentation. 68 + ''; 69 + example = lib.literalExpression '' 70 + { 71 + foo = ./foo; 72 + bar = pkgs.bar; 73 + } 74 + ''; 75 + }; 76 + 35 77 }; 36 78 37 79 config = lib.mkIf cfg.enable { 38 - environment = { 39 - systemPackages = [ cfg.package ]; 40 - variables.YAZI_CONFIG_HOME = "/etc/yazi/"; 41 - etc = lib.attrsets.mergeAttrsList (map 42 - (name: lib.optionalAttrs (cfg.settings.${name} != { }) { 43 - "yazi/${name}.toml".source = settingsFormat.generate "${name}.toml" cfg.settings.${name}; 44 - }) 45 - names); 46 - }; 80 + environment.systemPackages = [ 81 + (cfg.package.override { 82 + inherit (cfg) settings initLua plugins flavors; 83 + }) 84 + ]; 47 85 }; 86 + 48 87 meta = { 49 88 maintainers = with lib.maintainers; [ linsui ]; 50 89 };
+1 -1
pkgs/by-name/ya/yazi-unwrapped/package.nix
··· 44 44 description = "Blazing fast terminal file manager written in Rust, based on async I/O"; 45 45 homepage = "https://github.com/sxyazi/yazi"; 46 46 license = lib.licenses.mit; 47 - maintainers = with lib.maintainers; [ xyenon matthiasbeyer ]; 47 + maintainers = with lib.maintainers; [ xyenon matthiasbeyer linsui ]; 48 48 mainProgram = "yazi"; 49 49 }; 50 50 }
+43 -2
pkgs/by-name/ya/yazi/package.nix
··· 3 3 , makeWrapper 4 4 , yazi-unwrapped 5 5 6 + , withRuntimeDeps ? true 6 7 , withFile ? true 7 8 , file 8 9 , withJq ? true ··· 21 22 , fzf 22 23 , withZoxide ? true 23 24 , zoxide 25 + , settings ? { } 26 + , formats 27 + , plugins ? { } 28 + , flavors ? { } 29 + , initLua ? null 24 30 }: 25 31 26 32 let 27 - runtimePaths = with lib; [ ] 33 + runtimePaths = with lib; 34 + [ ] 28 35 ++ optional withFile file 29 36 ++ optional withJq jq 30 37 ++ optional withPoppler poppler_utils ··· 34 41 ++ optional withRipgrep ripgrep 35 42 ++ optional withFzf fzf 36 43 ++ optional withZoxide zoxide; 44 + 45 + settingsFormat = formats.toml { }; 46 + 47 + files = [ "yazi" "theme" "keymap" ]; 48 + 49 + configHome = if (settings == { } && initLua == null && plugins == { } && flavors == { }) then null else 50 + runCommand "YAZI_CONFIG_HOME" { } '' 51 + mkdir -p $out 52 + ${lib.concatMapStringsSep 53 + "\n" 54 + (name: lib.optionalString (settings ? ${name} && settings.${name} != { }) '' 55 + ln -s ${settingsFormat.generate "${name}.toml" settings.${name}} $out/${name}.toml 56 + '') 57 + files} 58 + 59 + mkdir $out/plugins 60 + ${lib.optionalString (plugins != { }) '' 61 + ${lib.concatMapStringsSep 62 + "\n" 63 + (lib.mapAttrsToList (name: value: "ln -s ${value} $out/plugins/${name}") plugins)} 64 + ''} 65 + 66 + mkdir $out/flavors 67 + ${lib.optionalString (flavors != { }) '' 68 + ${lib.concatMapStringsSep 69 + "\n" 70 + (lib.mapAttrsToList (name: value: "ln -s ${value} $out/flavors/${name}") flavors)} 71 + ''} 72 + 73 + 74 + ${lib.optionalString (initLua != null) "ln -s ${initLua} $out/init.lua"} 75 + ''; 37 76 in 77 + if (!withRuntimeDeps && configHome == null) then yazi-unwrapped else 38 78 runCommand yazi-unwrapped.name 39 79 { 40 80 inherit (yazi-unwrapped) pname version meta; ··· 44 84 mkdir -p $out/bin 45 85 ln -s ${yazi-unwrapped}/share $out/share 46 86 makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \ 47 - --prefix PATH : "${lib.makeBinPath runtimePaths}" 87 + ${lib.optionalString withRuntimeDeps "--prefix PATH : \"${lib.makeBinPath runtimePaths}\""} \ 88 + ${lib.optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"} 48 89 ''