Open suhr opened 4 years ago
But it's impossible to install it via r2pm in NixOS.
Why? What is the error?
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
All right, maybe it's possible to install with nix-shell
. But it's inconvenient and breakage-prone.
I have not looked into r2pm
and nix
yet. As you already found out it might be possible to compile it for now using nix-shell -p cmake
.
It partially compiles with nix-shell -p cmake bison flex
and then errors with no meaningful error message.
Creating a proper nixpkgs requires some patching though:
$ r2 -H R2_LIBR_PLUGINS
/nix/store/fgiv9xh85yj26vyq4f8lp51fnbm6a7n0-radare2-4.3.1/lib/radare2/4.3.1
$ r2 -H R2_USER_PLUGINS
/home/joerg/.local/share/radare2/plugins
Ideally radare2
would accept environment variables to load plugins from.
I tried this one:
$ git clone https://github.com/radareorg/r2ghidra-dec
$ cd r2ghidra-dec
$ git submodule update --init
$ cat > shell.nix <<EOF
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "env";
buildInputs = [
radare2
];
nativeBuildInputs = [
cmake bison flex
pkgconfig
];
}
EOF
$ nix-shell
$ mkdir build
$ cd build
$ cmake ..
$ make -j$(nproc)
It still does not compile. I assume the radare2 version in our repos is too old:
/home/joerg/git/r2ghidra-dec/src/R2TypeFactory.cpp: In member function ‘Datatype* R2TypeFactory::queryR2(const string&, std::set<std::__cxx11::basic_string<char> >&)’:
/home/joerg/git/r2ghidra-dec/src/R2TypeFactory.cpp:157:8: error: ‘R_TYPE_TYPEDEF’ was not declared in this scope
157 | case R_TYPE_TYPEDEF:
| ^~~~~~~~~~~~~~
/home/joerg/git/r2ghidra-dec/src/R2Scope.cpp: In member function ‘virtual bool R2Scope::isNameUsed(const string&) const’:
/home/joerg/git/r2ghidra-dec/src/R2Scope.cpp:590:6: error: ‘r_anal_get_function_byname’ was not declared in this scope; did you mean ‘r_anal_get_function_at’?
590 | if (r_anal_get_function_byname(core->anal, name.c_str()))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| r_anal_get_function_at
make[2]: *** [CMakeFiles/core_ghidra.dir/build.make:132: CMakeFiles/core_ghidra.dir/src/R2TypeFactory.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/core_ghidra.dir/build.make:119: CMakeFiles/core_ghidra.dir/src/R2Scope.cpp.o] Error 1
make[2]: Leaving directory '/home/joerg/git/r2ghidra-dec/build'
make[1]: *** [CMakeFiles/Makefile2:145: CMakeFiles/core_ghidra.dir/all] Error 2
make[1]: Leaving directory '/home/joerg/git/r2ghidra-dec/build'
make: *** [Makefile:147: all] Error 2
make: Leaving directory '/home/joerg/git/r2ghidra-dec/build'
It compiles with https://github.com/NixOS/nixpkgs/pull/86458
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/radare2-plugins-in-nixpkgs/8485/1
I marked this as stale due to inactivity. → More info
I wrote a rizin with plugins nix wrapper that also packages rz-ghidra, it may be helpful to anyone trying to package r2ghidra
Ideally
radare2
would accept environment variables to load plugins from.
radare2 already accepts R2_LIBR_PLUGINS
but that is just one path
feature request for multiple paths in https://github.com/radareorg/radare2/issues/21300
This is my attempt at packaging rz-ghidra https://github.com/NixOS/nixpkgs/pull/220885
With this, you can do
cutter.withPlugins (ps: with ps; [ rz-ghidra ])
rizin.withPlugins (ps: with ps; [ rz-ghidra ])
$ cat > shell.nix <<EOF
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "env";
buildInputs = [
radare2
];
nativeBuildInputs = [
cmake bison flex
pkgconfig
];
}
EOF
$ nix-shell
$ r2pm -ci r2ghidra
worked for me (no other actions needed r2 can find the plugin and start decompiling)
Radare2 allows using Ghidra as a decompiler: https://github.com/radareorg/r2ghidra-dec. But it's impossible to install it via r2pm in NixOS.
It would be nice to have a package that contains r2 together with Ghidra.
@Mic92