1 { lib, stdenv, fetchFromGitHub, lua, jemalloc, pkg-config
2 , tcl, which, ps, getconf
3 , withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, systemd
4 # dependency ordering is broken at the moment when building with openssl
5 , tlsSupport ? !stdenv.hostPlatform.isStatic, openssl
7 # Using system jemalloc fixes cross-compilation and various setups.
8 # However the experimental 'active defragmentation' feature of valkey requires
9 # their custom patched version of jemalloc.
10 , useSystemJemalloc ? true
13 stdenv.mkDerivation (finalAttrs: {
17 src = fetchFromGitHub {
20 rev = finalAttrs.version;
21 hash = "sha256-WB0blQLxQOTkK8UGsH6WISZAisUAtGIDfjoc4RnPSew=";
24 patches = lib.optional useSystemJemalloc ./use_system_jemalloc.patch;
26 nativeBuildInputs = [ pkg-config ];
29 ++ lib.optional useSystemJemalloc jemalloc
30 ++ lib.optional withSystemd systemd
31 ++ lib.optional tlsSupport openssl;
35 preBuild = lib.optionalString stdenv.hostPlatform.isDarwin ''
36 substituteInPlace src/Makefile --replace-fail "-flto" ""
39 # More cross-compiling fixes.
40 makeFlags = [ "PREFIX=${placeholder "out"}" ]
41 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "AR=${stdenv.cc.targetPrefix}ar" "RANLIB=${stdenv.cc.targetPrefix}ranlib" ]
42 ++ lib.optionals withSystemd [ "USE_SYSTEMD=yes" ]
43 ++ lib.optionals tlsSupport [ "BUILD_TLS=yes" ];
45 enableParallelBuilding = true;
47 hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ];
49 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [ "-std=c11" ]);
51 # darwin currently lacks a pure `pgrep` which is extensively used here
52 doCheck = !stdenv.hostPlatform.isDarwin;
53 nativeCheckInputs = [ which tcl ps ] ++ lib.optionals stdenv.hostPlatform.isStatic [ getconf ];
57 # disable test "Connect multiple replicas at the same time": even
58 # upstream find this test too timing-sensitive
59 substituteInPlace tests/integration/replication.tcl \
60 --replace-fail 'foreach mdl {no yes} dualchannel {no yes}' 'foreach mdl {} dualchannel {}'
62 substituteInPlace tests/support/server.tcl \
63 --replace-fail 'exec /usr/bin/env' 'exec env'
65 sed -i '/^proc wait_load_handlers_disconnected/{n ; s/wait_for_condition 50 100/wait_for_condition 50 500/; }' \
66 tests/support/util.tcl
71 --clients $NIX_BUILD_CORES \
73 --skipunit integration/failover # flaky and slow
79 homepage = "https://valkey.io/";
80 description = "High-performance data structure server that primarily serves key/value workloads";
81 license = licenses.bsd3;
82 platforms = platforms.all;
83 maintainers = with maintainers; [ rucadi ];
84 changelog = "https://github.com/valkey-io/valkey/releases/tag/${finalAttrs.version}";
85 mainProgram = "valkey-cli";