1{ lib
2, stdenv
3, fetchFromGitHub
4, autoreconfHook
5, pkg-config
6, libmysqlclient
7, libaio
8, luajit
9# For testing:
10, testers
11, sysbench
12}:
13
14stdenv.mkDerivation rec {
15 pname = "sysbench";
16 version = "1.0.20";
17
18 nativeBuildInputs = [ autoreconfHook pkg-config ];
19 buildInputs = [ libmysqlclient luajit ] ++ lib.optionals stdenv.isLinux [ libaio ];
20 depsBuildBuild = [ pkg-config ];
21
22 src = fetchFromGitHub {
23 owner = "akopytov";
24 repo = pname;
25 rev = version;
26 sha256 = "1sanvl2a52ff4shj62nw395zzgdgywplqvwip74ky8q7s6qjf5qy";
27 };
28
29 enableParallelBuilding = true;
30
31 configureFlags = [
32 # The bundled version does not build on aarch64-darwin:
33 # https://github.com/akopytov/sysbench/issues/416
34 "--with-system-luajit"
35 "--with-mysql-includes=${lib.getDev libmysqlclient}/include/mysql"
36 "--with-mysql-libs=${libmysqlclient}/lib/mysql"
37 ];
38
39 # We cannot use the regular nixpkgs ck here, since it has very
40 # different performance characteristics than the vendored one.
41 # On the downside the vendored libck version require more fixes for cross-compilation.
42 # Sysbench related on statically linked vendored libck.
43 postPatch = ''
44 substituteInPlace \
45 third_party/concurrency_kit/ck/configure \
46 --replace-fail \
47 'COMPILER=`./.1 2> /dev/null`' \
48 "COMPILER=${if stdenv.cc.isGNU then "gcc" else if stdenv.cc.isClang then "clang" else throw "Unsupported compiler"}" \
49 --replace-fail \
50 'PLATFORM=`uname -m 2> /dev/null`' \
51 "PLATFORM=${stdenv.hostPlatform.parsed.cpu.name}"
52 substituteInPlace \
53 third_party/concurrency_kit/ck/src/Makefile.in \
54 --replace-fail \
55 "ar rcs" \
56 "${stdenv.cc.targetPrefix}ar rcs"
57 '';
58
59 passthru.tests = {
60 versionTest = testers.testVersion {
61 package = sysbench;
62 };
63 };
64
65 meta = {
66 description = "Modular, cross-platform and multi-threaded benchmark tool";
67 mainProgram = "sysbench";
68 longDescription = ''
69 sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT.
70 It is most frequently used for database benchmarks, but can also be used
71 to create arbitrarily complex workloads that do not involve a database
72 server.
73 '';
74 homepage = "https://github.com/akopytov/sysbench";
75 downloadPage = "https://github.com/akopytov/sysbench/releases/tag/${version}";
76 changelog = "https://github.com/akopytov/sysbench/blob/${version}/ChangeLog";
77 license = lib.licenses.gpl2;
78 platforms = lib.platforms.unix;
79 };
80}