12 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
14 # dependency ordering is broken at the moment when building with openssl
15 tlsSupport ? !stdenv.hostPlatform.isStatic,
18 # Using system jemalloc fixes cross-compilation and various setups.
19 # However the experimental 'active defragmentation' feature of valkey requires
20 # their custom patched version of jemalloc.
21 useSystemJemalloc ? true,
24 stdenv.mkDerivation (finalAttrs: {
28 src = fetchFromGitHub {
31 rev = finalAttrs.version;
32 hash = "sha256-05EuPjVokzfJxhrnvFHD7prwt5y7gPxemeDIkLML7lw=";
35 patches = lib.optional useSystemJemalloc ./use_system_jemalloc.patch;
37 nativeBuildInputs = [ pkg-config ];
41 ++ lib.optional useSystemJemalloc jemalloc
42 ++ lib.optional withSystemd systemd
43 ++ lib.optional tlsSupport openssl;
47 preBuild = lib.optionalString stdenv.hostPlatform.isDarwin ''
48 substituteInPlace src/Makefile --replace-fail "-flto" ""
51 # More cross-compiling fixes.
53 [ "PREFIX=${placeholder "out"}" ]
54 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
55 "AR=${stdenv.cc.targetPrefix}ar"
56 "RANLIB=${stdenv.cc.targetPrefix}ranlib"
58 ++ lib.optionals withSystemd [ "USE_SYSTEMD=yes" ]
59 ++ lib.optionals tlsSupport [ "BUILD_TLS=yes" ];
61 enableParallelBuilding = true;
63 hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ];
65 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [ "-std=c11" ]);
67 # darwin currently lacks a pure `pgrep` which is extensively used here
68 doCheck = !stdenv.hostPlatform.isDarwin;
73 ] ++ lib.optionals stdenv.hostPlatform.isStatic [ getconf ];
77 # disable test "Connect multiple replicas at the same time": even
78 # upstream find this test too timing-sensitive
79 substituteInPlace tests/integration/replication.tcl \
80 --replace-fail 'foreach mdl {no yes} dualchannel {no yes}' 'foreach mdl {} dualchannel {}'
82 substituteInPlace tests/support/server.tcl \
83 --replace-fail 'exec /usr/bin/env' 'exec env'
85 sed -i '/^proc wait_load_handlers_disconnected/{n ; s/wait_for_condition 50 100/wait_for_condition 50 500/; }' \
86 tests/support/util.tcl
91 --clients $NIX_BUILD_CORES \
93 --skipunit integration/failover # flaky and slow
99 homepage = "https://valkey.io/";
100 description = "High-performance data structure server that primarily serves key/value workloads";
101 license = licenses.bsd3;
102 platforms = platforms.all;
103 maintainers = with maintainers; [ rucadi ];
104 changelog = "https://github.com/valkey-io/valkey/releases/tag/${finalAttrs.version}";
105 mainProgram = "valkey-cli";