From b32b614ffc09ec933a35087a6d4cf41483e32619 Mon Sep 17 00:00:00 2001 From: brunoproduit Date: Thu, 19 Feb 2026 14:56:00 +0100 Subject: [PATCH] flake: add nix flake for building remill Add a Nix flake that builds remill and its XED dependency using LLVM 17, with patched Ghidra sources for Sleigh. Co-Authored-By: Claude Opus 4.6 --- .gitignore | 3 ++ flake.lock | 27 ++++++++++++ flake.nix | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index cb39e512..98169e45 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ VERSION # Doxygen generated documentation docs/doxygen/ + +# Nix +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..f428ce80 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1767313136, + "narHash": "sha256-16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..d81cc7f0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,125 @@ +{ + description = "Remill - Static binary translator that lifts machine code to LLVM bitcode"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + + outputs = { self, nixpkgs }: + let + forSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; + in + { + packages = forSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + llvmPkgs = pkgs.llvmPackages_17; + + xed = llvmPkgs.stdenv.mkDerivation { + pname = "xed"; + version = "2025.06.08"; + + src = pkgs.fetchFromGitHub { + owner = "intelxed"; + repo = "xed"; + rev = "v2025.06.08"; + hash = "sha256-FXVWCq7ykuSsVx8iB7WkFD7DDq6o/4bgsS0YJQWE+XM="; + }; + + mbuild = pkgs.fetchFromGitHub { + owner = "intelxed"; + repo = "mbuild"; + rev = "v2024.11.04"; + hash = "sha256-iQVykBG3tEPxI1HmqBkvO1q+K8vi64qBfVC63/rcTOk="; + }; + + nativeBuildInputs = [ pkgs.python3 ]; + + dontConfigure = true; + + postUnpack = "cp -r $mbuild mbuild"; + + buildPhase = '' + runHook preBuild + patchShebangs . + python3 mfile.py install \ + --install-dir=$out \ + --cc=$CC --cxx=$CXX \ + --ar=$AR \ + --compiler=clang \ + --static \ + --extra-ccflags=-fPIC \ + --extra-cxxflags=-fPIC + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/lib/cmake/XED + cp ${./dependencies/XEDConfig.cmake.in} $out/lib/cmake/XED/XEDConfig.cmake + runHook postInstall + ''; + }; + + sleighSrc = pkgs.fetchFromGitHub { + owner = "lifting-bits"; + repo = "sleigh"; + rev = "7c6b742"; + hash = "sha256-Di/maGPXHPSM/EUVTgNRsu7nJ0Of+tVRu+B4wr9OoBE="; + }; + + ghidraSource = pkgs.applyPatches { + src = pkgs.fetchFromGitHub { + owner = "NationalSecurityAgency"; + repo = "ghidra"; + rev = "80ccdadeba79cd42fb0b85796b55952e0f79f323"; + hash = "sha256-7Iv1awZP5lU1LpGqC0nyiMxy0+3WOmM2NTdDYIzKmmk="; + }; + patches = + let dir = ./patches/sleigh; + in map (f: dir + "/${f}") + (builtins.filter (f: nixpkgs.lib.hasSuffix ".patch" f) + (builtins.sort builtins.lessThan + (builtins.attrNames (builtins.readDir dir)))); + }; + + remill = llvmPkgs.stdenv.mkDerivation { + pname = "remill"; + version = "0-unstable-${self.shortRev or self.dirtyShortRev or "unknown"}"; + + src = self; + + nativeBuildInputs = [ + pkgs.cmake + pkgs.ninja + pkgs.git + ]; + + buildInputs = [ + llvmPkgs.llvm.dev + llvmPkgs.llvm.lib + xed + pkgs.glog + pkgs.gflags + pkgs.gtest + ]; + + cmakeFlags = [ + "-DFETCHCONTENT_SOURCE_DIR_SLEIGH=${sleighSrc}" + "-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=${ghidraSource}" + "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" + "-DCLANG_PATH:FILEPATH=${pkgs.writeShellScript "bc-clang" '' + exec ${llvmPkgs.clang-unwrapped}/bin/clang++ \ + -resource-dir ${llvmPkgs.clang-unwrapped.lib}/lib/clang/17 \ + "$@" + ''}" + "-DREMILL_ENABLE_TESTING=OFF" + "-DGIT_FAIL_IF_NONZERO_EXIT=FALSE" + ]; + }; + in + { + default = remill; + inherit xed remill; + } + ); + }; +}