lol
1{ lib
2, stdenv
3, boost
4, cmake
5, fetchFromGitHub
6, fetchpatch
7, graphviz
8, igraph
9, llvmPackages
10, ninja
11, pkg-config
12, python3Packages
13, qtbase
14, qtsvg
15, quazip
16, rapidjson
17, spdlog
18, suitesparse
19, wrapQtAppsHook
20, z3
21}:
22
23let
24 # hal doesn't work with igraph 0.10.x yet https://github.com/emsec/hal/pull/487
25 igraph' = igraph.overrideAttrs (final: prev: {
26 version = "0.9.10";
27 src = fetchFromGitHub {
28 owner = "igraph";
29 repo = final.pname;
30 rev = final.version;
31 hash = "sha256-prDadHsNhDRkNp1i0niKIYxE0g85Zs0ngvUy6uK8evk=";
32 };
33 patches = (prev.patches or []) ++ [
34 # needed by clang
35 (fetchpatch {
36 name = "libxml2-2.11-compat.patch";
37 url = "https://github.com/igraph/igraph/commit/5ad464be5ae2f6ebb69c97cb0140c800cc8d97d6.patch";
38 hash = "sha256-adU5SctH+H54UaAmr5BZInytD3wjUzLtQbCwngAWs4o=";
39 })
40 ];
41 postPatch = prev.postPatch + lib.optionalString stdenv.isAarch64 ''
42 # https://github.com/igraph/igraph/issues/1694
43 substituteInPlace tests/CMakeLists.txt \
44 --replace "igraph_scg_grouping3" "" \
45 --replace "igraph_scg_semiprojectors2" ""
46 '';
47 # general options brought back from the old 0.9.x package
48 buildInputs = prev.buildInputs ++ [ suitesparse ];
49 cmakeFlags = prev.cmakeFlags ++ [ "-DIGRAPH_USE_INTERNAL_CXSPARSE=OFF" ];
50 });
51
52in stdenv.mkDerivation rec {
53 version = "4.2.0";
54 pname = "hal-hardware-analyzer";
55
56 src = fetchFromGitHub {
57 owner = "emsec";
58 repo = "hal";
59 rev = "v${version}";
60 sha256 = "sha256-Yl86AClE3vWygqj1omCOXX8koJK2SjTkMZFReRThez0=";
61 };
62
63 patches = [
64 (fetchpatch {
65 name = "cmake-add-no-vendored-options.patch";
66 # https://github.com/emsec/hal/pull/529
67 url = "https://github.com/emsec/hal/commit/37d5c1a0eacb25de57cc552c13e74f559a5aa6e8.patch";
68 hash = "sha256-a30VjDt4roJOTntisixqnH17wwCgWc4VWeh1+RgqFuY=";
69 })
70 (fetchpatch {
71 name = "hal-fix-fmt-10.1-compat.patch";
72 # https://github.com/emsec/hal/pull/530
73 url = "https://github.com/emsec/hal/commit/b639a56b303141afbf6731b70b7cc7452551f024.patch";
74 hash = "sha256-a7AyDEKkqdbiHpa4OHTRuP9Yewb3Nxs/j6bwez5m0yU=";
75 })
76 ];
77
78 # make sure bundled dependencies don't get in the way - install also otherwise
79 # copies them in full to the output, bloating the package
80 postPatch = ''
81 shopt -s extglob
82 rm -rf deps/!(abc|sanitizers-cmake|subprocess)/*
83 shopt -u extglob
84 '';
85
86 nativeBuildInputs = [
87 cmake
88 ninja
89 pkg-config
90 wrapQtAppsHook
91 ];
92 buildInputs = [
93 qtbase
94 qtsvg
95 boost
96 rapidjson
97 igraph'
98 spdlog
99 graphviz
100 z3
101 quazip
102 ]
103 ++ (with python3Packages; [ python pybind11 ])
104 ++ lib.optional stdenv.cc.isClang llvmPackages.openmp
105 ;
106
107 cmakeFlags = with lib.versions; [
108 "-DHAL_VERSION_RETURN=${version}"
109 "-DHAL_VERSION_MAJOR=${major version}"
110 "-DHAL_VERSION_MINOR=${minor version}"
111 "-DHAL_VERSION_PATCH=${patch version}"
112 "-DHAL_VERSION_TWEAK=0"
113 "-DHAL_VERSION_ADDITIONAL_COMMITS=0"
114 "-DHAL_VERSION_DIRTY=false"
115 "-DHAL_VERSION_BROKEN=false"
116 "-DENABLE_INSTALL_LDCONFIG=off"
117 "-DUSE_VENDORED_PYBIND11=off"
118 "-DUSE_VENDORED_SPDLOG=off"
119 "-DUSE_VENDORED_QUAZIP=off"
120 "-DUSE_VENDORED_IGRAPH=off"
121 "-DBUILD_ALL_PLUGINS=on"
122 ];
123 # needed for macos build - this is why we use wrapQtAppsHook instead of
124 # the qt mkDerivation - the latter forcibly overrides this.
125 cmakeBuildType = "MinSizeRel";
126
127 # some plugins depend on other plugins and need to be able to load them
128 postFixup = lib.optionalString stdenv.isLinux ''
129 find $out/lib/hal_plugins -name '*.so*' | while read -r f ; do
130 patchelf --set-rpath "$(patchelf --print-rpath "$f"):$out/lib/hal_plugins" "$f"
131 done
132 '';
133
134 meta = with lib; {
135 broken = stdenv.isDarwin;
136 description = "A comprehensive reverse engineering and manipulation framework for gate-level netlists";
137 homepage = "https://github.com/emsec/hal";
138 license = licenses.mit;
139 platforms = platforms.unix;
140 maintainers = with maintainers; [ ris shamilton ];
141 };
142}