summaryrefslogtreecommitdiff
path: root/pkgs/development/tools/analysis/rizin/wrapper.nix
blob: 17a910cb915256f6cb683cd595d08a0de660d27b (plain)
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
{
  lib,
  makeWrapper,
  symlinkJoin,
  plugins,
  rizin,
  isCutter ? false,
  cutter,
}:

let
  unwrapped = if isCutter then cutter else rizin;
in
symlinkJoin {
  name = "${unwrapped.pname}-with-plugins-${unwrapped.version}";

  # NIX_RZ_PREFIX only changes where *Rizin* locates files (plugins,
  # themes, etc). But we must change it even for wrapping Cutter, because
  # Cutter plugins often have associated Rizin plugins. This means that
  # $out (which NIX_RZ_PREFIX will be set to) must always contain Rizin
  # files, even if we only wrap Cutter - so for Cutter, include Rizin to
  # symlinkJoin paths.
  paths = [ unwrapped ] ++ lib.optional isCutter rizin ++ plugins;

  nativeBuildInputs = [ makeWrapper ];

  passthru = {
    inherit unwrapped;
  };

  postBuild = ''
    rm $out/bin/*
    wrapperArgs=(--set NIX_RZ_PREFIX $out${lib.optionalString isCutter " --prefix XDG_DATA_DIRS : $out/share"})
    for binary in $(ls ${unwrapped}/bin); do
      makeWrapper ${unwrapped}/bin/$binary $out/bin/$binary "''${wrapperArgs[@]}"
    done
  '';

  meta = unwrapped.meta // {
    # prefer wrapped over unwrapped
    priority = (unwrapped.meta.priority or lib.meta.defaultPriority) - 1;
  };
}