about summary refs log tree commit diff
path: root/pkgs/by-name/ya/yazi/package.nix
blob: ee807645c3fd485594826a1efcc86e4604f4050e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{ lib
, runCommand
, makeWrapper
, 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
}:

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;

  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
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}\""} \
    ${lib.optionalString (configHome != null) "--set YAZI_CONFIG_HOME ${configHome}"}
''