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