nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 cmake,
5 llvm,
6 fetchFromGitHub,
7 mbedtls,
8 gtk3,
9 pkg-config,
10 capstone,
11 dbus,
12 libGLU,
13 libGL,
14 glfw3,
15 file,
16 perl,
17 python3,
18 jansson,
19 curl,
20 fmt_11,
21 nlohmann_json,
22 yara,
23 nix-update-script,
24 autoPatchelfHook,
25 makeWrapper,
26}:
27
28let
29 version = "1.38.1";
30 patterns_version = "1.38.1";
31
32 patterns_src = fetchFromGitHub {
33 name = "ImHex-Patterns-source-${patterns_version}";
34 owner = "WerWolv";
35 repo = "ImHex-Patterns";
36 tag = "ImHex-v${patterns_version}";
37 hash = "sha256-MqQHzR5lKWhQI6pIX1kbAPDVG18UrMJM45mtIe/ggJE=";
38 };
39
40in
41stdenv.mkDerivation (finalAttrs: {
42 pname = "imhex";
43 inherit version;
44
45 src = fetchFromGitHub {
46 name = "ImHex-source-${version}";
47 fetchSubmodules = true;
48 owner = "WerWolv";
49 repo = "ImHex";
50 tag = "v${finalAttrs.version}";
51 hash = "sha256-lkpFiXuEF72nBkPuInv683Ct1Uu+uZ0PGejI9cVEUp0=";
52 };
53
54 strictDeps = true;
55
56 nativeBuildInputs = [
57 cmake
58 llvm
59 python3
60 perl
61 pkg-config
62 makeWrapper
63 ]
64 ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
65
66 buildInputs = [
67 capstone
68 curl
69 dbus
70 file
71 fmt_11
72 glfw3
73 gtk3
74 jansson
75 libGLU
76 mbedtls
77 nlohmann_json
78 yara
79 llvm
80 ];
81
82 # autoPatchelfHook only searches for *.so and *.so.*, and won't find *.hexpluglib
83 # however, we will append to RUNPATH ourselves
84 autoPatchelfIgnoreMissingDeps = lib.optionals stdenv.hostPlatform.isLinux [ "*.hexpluglib" ];
85 appendRunpaths = lib.optionals stdenv.hostPlatform.isLinux [
86 (lib.makeLibraryPath [ libGL ])
87 "${placeholder "out"}/lib/imhex/plugins"
88 ];
89
90 cmakeFlags = [
91 (lib.cmakeBool "IMHEX_OFFLINE_BUILD" true)
92 (lib.cmakeBool "IMHEX_COMPRESS_DEBUG_INFO" false) # avoids error: cannot compress debug sections (zstd not enabled)
93 (lib.cmakeBool "IMHEX_GENERATE_PACKAGE" stdenv.hostPlatform.isDarwin)
94 (lib.cmakeBool "USE_SYSTEM_CAPSTONE" true)
95 (lib.cmakeBool "USE_SYSTEM_CURL" true)
96 (lib.cmakeBool "USE_SYSTEM_FMT" true)
97 (lib.cmakeBool "USE_SYSTEM_LLVM" true)
98 (lib.cmakeBool "USE_SYSTEM_NLOHMANN_JSON" true)
99 (lib.cmakeBool "USE_SYSTEM_YARA" true)
100 (lib.cmakeFeature "CMAKE_POLICY_VERSION_MINIMUM" "3.5")
101 ];
102
103 env.NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
104
105 # Comment out fixup_bundle in PostprocessBundle.cmake as we are not building a standalone application
106 postPatch = ''
107 # Link patterns source into location expected by cmake when IMHEX_OFFLINE_BUILD is set
108 ln -s ${patterns_src} ImHex-Patterns
109 ''
110 + lib.optionalString stdenv.hostPlatform.isDarwin ''
111 substituteInPlace cmake/modules/PostprocessBundle.cmake \
112 --replace-fail "fixup_bundle" "#fixup_bundle"
113 '';
114
115 postInstall =
116 if stdenv.hostPlatform.isLinux then
117 ''
118 # without this imhex is not able to find pattern files
119 wrapProgram $out/bin/imhex --prefix XDG_DATA_DIRS : $out/share
120 ''
121 else if stdenv.hostPlatform.isDarwin then
122 ''
123 mkdir -p $out/Applications
124 mv $out/imhex.app $out/Applications
125 install_name_tool \
126 -change "$out/lib/libimhex.${finalAttrs.version}${stdenv.hostPlatform.extensions.sharedLibrary}" \
127 "@executable_path/../Frameworks/libimhex.${finalAttrs.version}${stdenv.hostPlatform.extensions.sharedLibrary}" \
128 "$out/Applications/imhex.app/Contents/MacOS/imhex"
129 makeWrapper "$out/Applications/imhex.app/Contents/MacOS/imhex" "$out/bin/imhex"
130 ''
131 else
132 throw "Unsupported system";
133
134 passthru.updateScript = nix-update-script { };
135
136 meta = {
137 description = "Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM";
138 homepage = "https://github.com/WerWolv/ImHex";
139 license = with lib.licenses; [ gpl2Only ];
140 maintainers = with lib.maintainers; [
141 kashw2
142 cafkafk
143 govanify
144 ryand56
145 ];
146 platforms = with lib.platforms; linux ++ darwin;
147 };
148})