12 , enableJemalloc ? false
14 , enableLiburing ? stdenv.hostPlatform.isLinux
16 , enableShared ? !stdenv.hostPlatform.isStatic
17 , sse42Support ? stdenv.hostPlatform.sse4_2Support
20 stdenv.mkDerivation (finalAttrs: {
24 src = fetchFromGitHub {
27 rev = "v${finalAttrs.version}";
28 hash = "sha256-HeC7m9ZK7SIU7adkQEurzHf+MY7AiEwXZQaz9uZZncU=";
31 patches = lib.optional (lib.versionAtLeast finalAttrs.version "6.29.3" && enableLiburing) ./fix-findliburing.patch;
33 nativeBuildInputs = [ cmake ninja ];
35 propagatedBuildInputs = [ bzip2 lz4 snappy zlib zstd ];
37 buildInputs = lib.optional enableJemalloc jemalloc
38 ++ lib.optional enableLiburing liburing
39 ++ lib.optional stdenv.hostPlatform.isMinGW windows.mingw_w64_pthreads;
46 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [
47 "-faligned-allocation"
52 "-DWITH_JEMALLOC=${if enableJemalloc then "1" else "0"}"
53 "-DWITH_LIBURING=${if enableLiburing then "1" else "0"}"
55 "-DWITH_BENCHMARK_TOOLS=0"
66 "-DROCKSDB_INSTALL_ON_WINDOWS=YES" # harmless elsewhere
67 (lib.optional sse42Support "-DFORCE_SSE42=1")
68 "-DFAIL_ON_WARNINGS=NO"
69 ] ++ lib.optional (!enableShared) "-DROCKSDB_BUILD_SHARED=0";
71 # otherwise "cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]"
72 hardeningDisable = lib.optional stdenv.hostPlatform.isWindows "format";
74 postPatch = lib.optionalString (lib.versionOlder finalAttrs.version "8") ''
75 # Fix gcc-13 build failures due to missing <cstdint> and
76 # <system_error> includes, fixed upstyream sice 8.x
77 sed -e '1i #include <cstdint>' -i db/compaction/compaction_iteration_stats.h
78 sed -e '1i #include <cstdint>' -i table/block_based/data_block_hash_index.h
79 sed -e '1i #include <cstdint>' -i util/string_util.h
80 sed -e '1i #include <cstdint>' -i include/rocksdb/utilities/checkpoint.h
81 '' + lib.optionalString (lib.versionOlder finalAttrs.version "7") ''
82 # Fix gcc-13 build failures due to missing <cstdint> and
83 # <system_error> includes, fixed upstyream sice 7.x
84 sed -e '1i #include <system_error>' -i third-party/folly/folly/synchronization/detail/ProxyLockable-inl.h
89 cp tools/{ldb,sst_dump}${stdenv.hostPlatform.extensions.executable} $tools/bin/
90 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
91 ls -1 $tools/bin/* | xargs -I{} install_name_tool -change "@rpath/librocksdb.${lib.versions.major finalAttrs.version}.dylib" $out/lib/librocksdb.dylib {}
92 '' + lib.optionalString (stdenv.hostPlatform.isLinux && enableShared) ''
93 ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${lib.getLib stdenv.cc.cc}/lib {}
96 # Old version doesn't ship the .pc file, new version puts wrong paths in there.
98 if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then
99 substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \
100 --replace '="''${prefix}//' '="/'
105 homepage = "https://rocksdb.org";
106 description = "Library that provides an embeddable, persistent key-value store for fast storage";
107 changelog = "https://github.com/facebook/rocksdb/raw/v${finalAttrs.version}/HISTORY.md";
108 license = licenses.asl20;
109 platforms = platforms.all;
110 maintainers = with maintainers; [ adev magenbluten ];