22 lib ,
33 stdenv ,
44 cmake ,
5- llvm ,
5+ darwin ,
6+ fetchpatch ,
7+ llvmPackages_17 ,
68 fetchFromGitHub ,
79 mbedtls ,
810 gtk3 ,
2123 nlohmann_json ,
2224 yara ,
2325 rsync ,
26+ nix-update-script ,
2427 autoPatchelfHook ,
28+ makeWrapper ,
29+ overrideSDK ,
2530} :
2631
2732let
2833 version = "1.35.4" ;
2934 patterns_version = "1.35.4" ;
3035
36+ llvmPackages = llvmPackages_17 ;
37+
38+ stdenv' =
39+ let
40+ baseStdenv = if stdenv . cc . isClang then llvmPackages . stdenv else stdenv ;
41+ in
42+ if stdenv . isDarwin then overrideSDK baseStdenv "11.0" else baseStdenv ;
43+
3144 patterns_src = fetchFromGitHub {
3245 name = "ImHex-Patterns-source-${ patterns_version } " ;
3346 owner = "WerWolv" ;
3750 } ;
3851
3952in
40- stdenv . mkDerivation rec {
53+ stdenv' . mkDerivation ( finalAttrs : {
4154 pname = "imhex" ;
4255 inherit version ;
4356
@@ -46,20 +59,39 @@ stdenv.mkDerivation rec {
4659 fetchSubmodules = true ;
4760 owner = "WerWolv" ;
4861 repo = "ImHex" ;
49- rev = "refs/tags/v${ version } " ;
62+ rev = "refs/tags/v${ finalAttrs . version } " ;
5063 hash = "sha256-6QpmFkSMQpGlEzo7BHZn20c+q8CTDUB4yO87wMU5JT4=" ;
5164 } ;
5265
53- nativeBuildInputs = [
54- autoPatchelfHook
55- cmake
56- llvm
57- python3
58- perl
59- pkg-config
60- rsync
66+ patches = [
67+ # https://github.com/WerWolv/ImHex/pull/1910
68+ # during https://github.com/NixOS/nixpkgs/pull/330303 it was discovered that ImHex
69+ # would not build on Darwin x86-64
70+ # this temporary patch can be removed when the above PR is merged
71+ ( fetchpatch {
72+ url = "https://github.com/WerWolv/ImHex/commit/69624a2661ea44db9fb8b81c3278ef69016ebfcf.patch" ;
73+ hash = "sha256-LcUCl8Rfz6cbhop2StksuViim2bH4ma3/8tGVKFdAgg=" ;
74+ } )
6175 ] ;
6276
77+ # Comment out fixup_bundle in PostprocessBundle.cmake as we are not building a standalone application
78+ postPatch = lib . optionalString stdenv . isDarwin ''
79+ substituteInPlace cmake/modules/PostprocessBundle.cmake \
80+ --replace-fail "fixup_bundle" "#fixup_bundle"
81+ '' ;
82+
83+ nativeBuildInputs =
84+ [
85+ cmake
86+ llvmPackages . llvm
87+ python3
88+ perl
89+ pkg-config
90+ rsync
91+ ]
92+ ++ lib . optionals stdenv . isLinux [ autoPatchelfHook ]
93+ ++ lib . optionals stdenv . isDarwin [ makeWrapper ] ;
94+
6395 buildInputs = [
6496 capstone
6597 curl
@@ -73,31 +105,50 @@ stdenv.mkDerivation rec {
73105 mbedtls
74106 nlohmann_json
75107 yara
76- ] ;
108+ ] ++ lib . optionals stdenv . isDarwin [ darwin . apple_sdk_11_0 . frameworks . UniformTypeIdentifiers ] ;
77109
78110 # autoPatchelfHook only searches for *.so and *.so.*, and won't find *.hexpluglib
79111 # however, we will append to RUNPATH ourselves
80- autoPatchelfIgnoreMissingDeps = [ "*.hexpluglib" ] ;
81- appendRunpaths = [
112+ autoPatchelfIgnoreMissingDeps = lib . optionals stdenv . isLinux [ "*.hexpluglib" ] ;
113+ appendRunpaths = lib . optionals stdenv . isLinux [
82114 ( lib . makeLibraryPath [ libGL ] )
83115 "${ placeholder "out" } /lib/imhex/plugins"
84116 ] ;
85117
86118 cmakeFlags = [
87- "-DIMHEX_OFFLINE_BUILD=ON"
88- "-DUSE_SYSTEM_CAPSTONE=ON"
89- "-DUSE_SYSTEM_CURL=ON"
90- "-DUSE_SYSTEM_FMT=ON"
91- "-DUSE_SYSTEM_LLVM=ON"
92- "-DUSE_SYSTEM_NLOHMANN_JSON=ON"
93- "-DUSE_SYSTEM_YARA=ON"
119+ ( lib . cmakeBool "IMHEX_OFFLINE_BUILD" true )
120+ ( lib . cmakeBool "IMHEX_COMPRESS_DEBUG_INFO" false ) # avoids error: cannot compress debug sections (zstd not enabled)
121+ ( lib . cmakeBool "IMHEX_GENERATE_PACKAGE" stdenv . isDarwin )
122+ ( lib . cmakeBool "USE_SYSTEM_CAPSTONE" true )
123+ ( lib . cmakeBool "USE_SYSTEM_CURL" true )
124+ ( lib . cmakeBool "USE_SYSTEM_FMT" true )
125+ ( lib . cmakeBool "USE_SYSTEM_LLVM" true )
126+ ( lib . cmakeBool "USE_SYSTEM_NLOHMANN_JSON" true )
127+ ( lib . cmakeBool "USE_SYSTEM_YARA" true )
94128 ] ;
95129
96130 # rsync is used here so we can not copy the _schema.json files
97- postInstall = ''
98- mkdir -p $out/share/imhex
99- rsync -av --exclude="*_schema.json" ${ patterns_src } /{constants,encodings,includes,magic,patterns} $out/share/imhex
100- '' ;
131+ postInstall =
132+ if stdenv . isLinux then
133+ ''
134+ mkdir -p $out/share/imhex
135+ rsync -av --exclude="*_schema.json" ${ patterns_src } /{constants,encodings,includes,magic,nodes,patterns} $out/share/imhex
136+ ''
137+ else if stdenv . isDarwin then
138+ ''
139+ mkdir -p $out/Applications
140+ mv $out/imhex.app $out/Applications
141+ rsync -av --exclude="*_schema.json" ${ patterns_src } /{constants,encodings,includes,magic,nodes,patterns} "$out/Applications/imhex.app/Contents/MacOS"
142+ install_name_tool \
143+ -change "$out/lib/libimhex.${ finalAttrs . version } ${ stdenv . hostPlatform . extensions . sharedLibrary } " \
144+ "@executable_path/../Frameworks/libimhex.${ finalAttrs . version } ${ stdenv . hostPlatform . extensions . sharedLibrary } " \
145+ "$out/Applications/imhex.app/Contents/MacOS/imhex"
146+ makeWrapper "$out/Applications/imhex.app/Contents/MacOS/imhex" "$out/bin/imhex"
147+ ''
148+ else
149+ throw "Unsupported system" ;
150+
151+ passthru . updateScript = nix-update-script { } ;
101152
102153 meta = with lib ; {
103154 description = "Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM" ;
@@ -107,6 +158,6 @@ stdenv.mkDerivation rec {
107158 kashw2
108159 cafkafk
109160 ] ;
110- platforms = platforms . linux ;
161+ platforms = platforms . linux ++ platforms . darwin ;
111162 } ;
112- }
163+ } )
0 commit comments