nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, cmake
6, ninja
7, bzip2
8, lz4
9, snappy
10, zlib
11, zstd
12, windows
13, enableJemalloc ? false
14, jemalloc
15, enableLite ? false
16, enableShared ? !stdenv.hostPlatform.isStatic
17, sse42Support ? stdenv.hostPlatform.sse4_2Support
18}:
19
20stdenv.mkDerivation rec {
21 pname = "rocksdb";
22 version = "7.10.2";
23
24 src = fetchFromGitHub {
25 owner = "facebook";
26 repo = pname;
27 rev = "v${version}";
28 sha256 = "sha256-U2ReSrJwjAXUdRmwixC0DQXht/h/6rV8SOf5e2NozIs=";
29 };
30
31 nativeBuildInputs = [ cmake ninja ];
32
33 propagatedBuildInputs = [ bzip2 lz4 snappy zlib zstd ];
34
35 buildInputs = lib.optional enableJemalloc jemalloc
36 ++ lib.optional stdenv.hostPlatform.isMinGW windows.mingw_w64_pthreads;
37
38 outputs = [
39 "out"
40 "tools"
41 ];
42
43 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isGNU [
44 "-Wno-error=deprecated-copy"
45 "-Wno-error=pessimizing-move"
46 # Needed with GCC 12
47 "-Wno-error=format-truncation"
48 "-Wno-error=maybe-uninitialized"
49 ] ++ lib.optionals stdenv.cc.isClang [
50 "-Wno-error=unused-private-field"
51 "-faligned-allocation"
52 ]);
53
54 cmakeFlags = [
55 "-DPORTABLE=1"
56 "-DWITH_JEMALLOC=${if enableJemalloc then "1" else "0"}"
57 "-DWITH_JNI=0"
58 "-DWITH_BENCHMARK_TOOLS=0"
59 "-DWITH_TESTS=1"
60 "-DWITH_TOOLS=0"
61 "-DWITH_CORE_TOOLS=1"
62 "-DWITH_BZ2=1"
63 "-DWITH_LZ4=1"
64 "-DWITH_SNAPPY=1"
65 "-DWITH_ZLIB=1"
66 "-DWITH_ZSTD=1"
67 "-DWITH_GFLAGS=0"
68 "-DUSE_RTTI=1"
69 "-DROCKSDB_INSTALL_ON_WINDOWS=YES" # harmless elsewhere
70 (lib.optional sse42Support "-DFORCE_SSE42=1")
71 (lib.optional enableLite "-DROCKSDB_LITE=1")
72 "-DFAIL_ON_WARNINGS=${if stdenv.hostPlatform.isMinGW then "NO" else "YES"}"
73 ] ++ lib.optional (!enableShared) "-DROCKSDB_BUILD_SHARED=0";
74
75 # otherwise "cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]"
76 hardeningDisable = lib.optional stdenv.hostPlatform.isWindows "format";
77
78 preInstall = ''
79 mkdir -p $tools/bin
80 cp tools/{ldb,sst_dump}${stdenv.hostPlatform.extensions.executable} $tools/bin/
81 '' + lib.optionalString stdenv.isDarwin ''
82 ls -1 $tools/bin/* | xargs -I{} install_name_tool -change "@rpath/librocksdb.7.dylib" $out/lib/librocksdb.dylib {}
83 '' + lib.optionalString (stdenv.isLinux && enableShared) ''
84 ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib {}
85 '';
86
87 # Old version doesn't ship the .pc file, new version puts wrong paths in there.
88 postFixup = ''
89 if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then
90 substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \
91 --replace '="''${prefix}//' '="/'
92 fi
93 '';
94
95 meta = with lib; {
96 homepage = "https://rocksdb.org";
97 description = "A library that provides an embeddable, persistent key-value store for fast storage";
98 changelog = "https://github.com/facebook/rocksdb/raw/v${version}/HISTORY.md";
99 license = licenses.asl20;
100 platforms = platforms.all;
101 maintainers = with maintainers; [ adev magenbluten ];
102 };
103}