nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 boost,
5 cmake,
6 fetchFromGitHub,
7 fetchpatch,
8 graphviz,
9 igraph,
10 llvmPackages,
11 ninja,
12 nlohmann_json,
13 pkg-config,
14 python3Packages,
15 qtbase,
16 qtsvg,
17 quazip,
18 rapidjson,
19 spdlog,
20 verilator,
21 wrapQtAppsHook,
22 z3,
23}:
24
25stdenv.mkDerivation rec {
26 version = "4.4.1";
27 pname = "hal-hardware-analyzer";
28
29 src = fetchFromGitHub {
30 owner = "emsec";
31 repo = "hal";
32 rev = "v${version}";
33 sha256 = "sha256-8kmYeqsmqR7tY044rZb3KuEAVGv37IObX6k1qjXWG0A=";
34 };
35
36 patches = [
37 (fetchpatch {
38 name = "de-vendor-nlohmann-json.patch";
39 # https://github.com/emsec/hal/pull/596
40 url = "https://github.com/emsec/hal/commit/f8337d554d80cfa2588512696696fd4c878dd7a3.patch";
41 hash = "sha256-QjgvcduwbFccC807JFOevlTfO3KiL9T3HSqYmh3sXAQ=";
42 })
43 (fetchpatch {
44 name = "fix-vendored-igraph-regression.patch";
45 # https://github.com/emsec/hal/pull/596
46 url = "https://github.com/emsec/hal/commit/fe1fe74719ab4fef873a22e2b28cce0c57d570e0.patch";
47 hash = "sha256-bjbW4pr04pP0TCuSdzPcV8h6LbLWMvdGSf61RL9Ju6E=";
48 })
49 ./4.4.1-newer-spdlog-fmt-compat.patch
50 ./resynthesis-fix-narrowing-conversion.patch
51 ];
52
53 # make sure bundled dependencies don't get in the way - install also otherwise
54 # copies them in full to the output, bloating the package
55 postPatch = ''
56 shopt -s extglob
57 rm -rf deps/!(abc|sanitizers-cmake|subprocess)/*
58 shopt -u extglob
59 # https://github.com/emsec/hal/issues/602
60 sed -i 1i'#include <algorithm>' include/hal_core/utilities/utils.h
61 '';
62
63 nativeBuildInputs = [
64 cmake
65 ninja
66 pkg-config
67 wrapQtAppsHook
68 ];
69 buildInputs = [
70 qtbase
71 qtsvg
72 boost
73 rapidjson
74 igraph
75 nlohmann_json
76 spdlog
77 graphviz
78 verilator
79 z3
80 quazip
81 ]
82 ++ (with python3Packages; [
83 python
84 pybind11
85 ])
86 ++ lib.optional stdenv.cc.isClang llvmPackages.openmp;
87
88 cmakeFlags = with lib.versions; [
89 "-DHAL_VERSION_RETURN=${version}"
90 "-DHAL_VERSION_MAJOR=${major version}"
91 "-DHAL_VERSION_MINOR=${minor version}"
92 "-DHAL_VERSION_PATCH=${patch version}"
93 "-DHAL_VERSION_TWEAK=0"
94 "-DHAL_VERSION_ADDITIONAL_COMMITS=0"
95 "-DHAL_VERSION_DIRTY=false"
96 "-DHAL_VERSION_BROKEN=false"
97 "-DENABLE_INSTALL_LDCONFIG=off"
98 "-DUSE_VENDORED_PYBIND11=off"
99 "-DUSE_VENDORED_SPDLOG=off"
100 "-DUSE_VENDORED_QUAZIP=off"
101 "-DUSE_VENDORED_IGRAPH=off"
102 "-DUSE_VENDORED_NLOHMANN_JSON=off"
103 "-DBUILD_ALL_PLUGINS=on"
104 ];
105 # needed for macos build - this is why we use wrapQtAppsHook instead of
106 # the qt mkDerivation - the latter forcibly overrides this.
107 cmakeBuildType = "MinSizeRel";
108
109 # https://github.com/emsec/hal/issues/598
110 NIX_CFLAGS_COMPILE = lib.optional stdenv.hostPlatform.isAarch64 "-flax-vector-conversions";
111
112 # some plugins depend on other plugins and need to be able to load them
113 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
114 find $out/lib/hal_plugins -name '*.so*' | while read -r f ; do
115 patchelf --set-rpath "$(patchelf --print-rpath "$f"):$out/lib/hal_plugins" "$f"
116 done
117 '';
118
119 meta = with lib; {
120 description = "Comprehensive reverse engineering and manipulation framework for gate-level netlists";
121 mainProgram = "hal";
122 homepage = "https://github.com/emsec/hal";
123 license = licenses.mit;
124 platforms = platforms.unix;
125 maintainers = with maintainers; [
126 ris
127 shamilton
128 ];
129 };
130}