1{ lib
2, pkgs # for passthru.plugins
3, stdenv
4, fetchurl
5, pkg-config
6, libusb-compat-0_1
7, readline
8, libewf
9, perl
10, zlib
11, openssl
12, file
13, libmspack
14, libzip
15, lz4
16, xxHash
17, xz
18, meson
19, python3
20, cmake
21, ninja
22, capstone
23, tree-sitter
24}:
25
26let rizin = stdenv.mkDerivation rec {
27 pname = "rizin";
28 version = "0.6.3";
29
30 src = fetchurl {
31 url = "https://github.com/rizinorg/rizin/releases/download/v${version}/rizin-src-v${version}.tar.xz";
32 hash = "sha256-lfZMarnm2qnp+lY0OY649s206/LoFNouTLlp0x9FCcI=";
33 };
34
35 mesonFlags = [
36 "-Duse_sys_capstone=enabled"
37 "-Duse_sys_magic=enabled"
38 "-Duse_sys_libzip=enabled"
39 "-Duse_sys_zlib=enabled"
40 "-Duse_sys_lz4=enabled"
41 "-Duse_sys_lzma=enabled"
42 "-Duse_sys_xxhash=enabled"
43 "-Duse_sys_openssl=enabled"
44 "-Duse_sys_libmspack=enabled"
45 "-Duse_sys_tree_sitter=enabled"
46 # this is needed for wrapping (adding plugins) to work
47 "-Dportable=true"
48 ];
49
50 # Normally, Rizin only looks for files in the install prefix. With
51 # portable=true, it instead looks for files in relation to the parent
52 # of the directory of the binary file specified in /proc/self/exe,
53 # caching it. This patch replaces the entire logic to only look at
54 # the env var NIX_RZ_PREFIX
55 patches = [ ./librz-wrapper-support.patch ];
56
57 nativeBuildInputs = [
58 pkg-config
59 meson
60 (python3.withPackages (pp: with pp; [
61 pyyaml
62 ]))
63 ninja
64 cmake
65 ];
66
67 # meson's find_library seems to not use our compiler wrapper if static parameter
68 # is either true/false... We work around by also providing LIBRARY_PATH
69 preConfigure = ''
70 LIBRARY_PATH=""
71 for b in ${toString (map lib.getLib buildInputs)}; do
72 if [[ -d "$b/lib" ]]; then
73 LIBRARY_PATH="$b/lib''${LIBRARY_PATH:+:}$LIBRARY_PATH"
74 fi
75 done
76 export LIBRARY_PATH
77 '' + lib.optionalString stdenv.isDarwin ''
78 substituteInPlace binrz/rizin/macos_sign.sh \
79 --replace 'codesign' '# codesign'
80 '';
81
82 buildInputs = [
83 file
84 libzip
85 capstone
86 readline
87 libusb-compat-0_1
88 libewf
89 perl
90 zlib
91 lz4
92 openssl
93 libmspack
94 tree-sitter
95 xxHash
96 xz
97 ];
98
99 postPatch = ''
100 # find_installation without arguments uses Meson’s Python interpreter,
101 # which does not have any extra modules.
102 # https://github.com/mesonbuild/meson/pull/9904
103 substituteInPlace meson.build \
104 --replace "import('python').find_installation()" "find_program('python3')"
105 '';
106
107 passthru = rec {
108 plugins = {
109 jsdec = pkgs.callPackage ./jsdec.nix {
110 inherit rizin openssl;
111 };
112 rz-ghidra = pkgs.libsForQt5.callPackage ./rz-ghidra.nix {
113 inherit rizin openssl;
114 enableCutterPlugin = false;
115 };
116 # sigdb isn't a real plugin, but it's separated from the main rizin
117 # derivation so that only those who need it will download it
118 sigdb = pkgs.callPackage ./sigdb.nix { };
119 };
120 withPlugins = filter: pkgs.callPackage ./wrapper.nix {
121 inherit rizin;
122 plugins = filter plugins;
123 };
124 };
125
126 meta = {
127 description = "UNIX-like reverse engineering framework and command-line toolset.";
128 homepage = "https://rizin.re/";
129 license = lib.licenses.gpl3Plus;
130 mainProgram = "rizin";
131 maintainers = with lib.maintainers; [ raskin makefu mic92 ];
132 platforms = with lib.platforms; unix;
133 };
134}; in rizin