Unverified Commit 24b44a1f authored by Aleksana's avatar Aleksana Committed by GitHub
Browse files

Merge pull request #321076 from eljamm/yazi

yazi: clean up wrapper, add options and format 
parents 3ab84ecc 1f6b8d25
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ rustPlatform.buildRustPackage rec {
    description = "Blazing fast terminal file manager written in Rust, based on async I/O";
    homepage = "https://github.com/sxyazi/yazi";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ xyenon matthiasbeyer linsui ];
    maintainers = with lib.maintainers; [ xyenon matthiasbeyer linsui eljamm ];
    mainProgram = "yazi";
  };
}
+78 −74
Original line number Diff line number Diff line
{ lib
, runCommand
, makeWrapper
, yazi-unwrapped
{
  lib,
  formats,
  runCommand,
  makeWrapper,

  extraPackages ? [ ],
  optionalDeps ? [
    jq
    poppler_utils
    unar
    ffmpegthumbnailer
    fd
    ripgrep
    fzf
    zoxide
  ],

  # deps
  file,
  yazi-unwrapped,

, withRuntimeDeps ? true
, withFile ? true
, file
, withJq ? true
, jq
, withPoppler ? true
, poppler_utils
, withUnar ? true
, unar
, withFfmpegthumbnailer ? true
, ffmpegthumbnailer
, withFd ? true
, fd
, withRipgrep ? true
, ripgrep
, withFzf ? true
, fzf
, withZoxide ? true
, zoxide
, settings ? { }
, formats
, plugins ? { }
, flavors ? { }
, initLua ? null
  # optional deps
  jq,
  poppler_utils,
  unar,
  ffmpegthumbnailer,
  fd,
  ripgrep,
  fzf,
  zoxide,

  settings ? { },
  plugins ? { },
  flavors ? { },
  initLua ? null,
}:

let
  runtimePaths = with lib;
    [ ]
    ++ optional withFile file
    ++ optional withJq jq
    ++ optional withPoppler poppler_utils
    ++ optional withUnar unar
    ++ optional withFfmpegthumbnailer ffmpegthumbnailer
    ++ optional withFd fd
    ++ optional withRipgrep ripgrep
    ++ optional withFzf fzf
    ++ optional withZoxide zoxide;
  runtimePaths = [ file ] ++ optionalDeps ++ extraPackages;

  settingsFormat = formats.toml { };

  files = [ "yazi" "theme" "keymap" ];
  files = [
    "yazi"
    "theme"
    "keymap"
  ];

  configHome = if (settings == { } && initLua == null && plugins == { } && flavors == { }) then null else
  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} != { }) ''
        ${lib.concatMapStringsSep "\n" (
          name:
          lib.optionalString (settings ? ${name} && settings.${name} != { }) ''
            ln -s ${settingsFormat.generate "${name}.toml" settings.${name}} $out/${name}.toml
      '')
      files}
          ''
        ) files}

        mkdir $out/plugins
        ${lib.optionalString (plugins != { }) ''
        ${lib.concatStringsSep
        "\n"
        (lib.mapAttrsToList (name: value: "ln -s ${value} $out/plugins/${name}") plugins)}
          ${lib.concatStringsSep "\n" (
            lib.mapAttrsToList (name: value: "ln -s ${value} $out/plugins/${name}") plugins
          )}
        ''}

        mkdir $out/flavors
        ${lib.optionalString (flavors != { }) ''
        ${lib.concatStringsSep
        "\n"
        (lib.mapAttrsToList (name: value: "ln -s ${value} $out/flavors/${name}") flavors)}
          ${lib.concatStringsSep "\n" (
            lib.mapAttrsToList (name: value: "ln -s ${value} $out/flavors/${name}") flavors
          )}
        ''}


        ${lib.optionalString (initLua != null) "ln -s ${initLua} $out/init.lua"}
      '';
in
if (!withRuntimeDeps && configHome == null) then yazi-unwrapped else
runCommand yazi-unwrapped.name
  {
    inherit (yazi-unwrapped) pname version meta;

    nativeBuildInputs = [ makeWrapper ];
} ''
  }
  ''
    mkdir -p $out/bin
    ln -s ${yazi-unwrapped}/share $out/share
    makeWrapper ${yazi-unwrapped}/bin/yazi $out/bin/yazi \
    ${lib.optionalString withRuntimeDeps "--prefix PATH : \"${lib.makeBinPath runtimePaths}\""} \
      --prefix PATH : ${lib.makeBinPath runtimePaths} \
      ${lib.optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"}
  ''