about summary refs log tree commit diff
path: root/pkgs/by-name/ke/keydb/package.nix
blob: 3fc085b40ad9f22c32ebd560839b97ea2a33a441 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
  stdenv,
  lib,
  fetchFromGitHub,
  libuuid,
  curl,
  pkg-config,
  withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
  systemd,
  tlsSupport ? !stdenv.hostPlatform.isStatic,
  openssl,
  jemalloc,
  which,
  tcl,
  tcltls,
  ps,
  getconf,
  nixosTests,
}:

stdenv.mkDerivation rec {
  pname = "keydb";
  version = "6.3.4";

  src = fetchFromGitHub {
    owner = "snapchat";
    repo = "keydb";
    rev = "v${version}";
    hash = "sha256-j6qgK6P3Fv+b6k9jwKQ5zW7XLkKbXXcmHKBCQYvwEIU=";
  };

  postPatch = ''
    substituteInPlace deps/lua/src/Makefile \
      --replace-fail "ar rcu" "${stdenv.cc.targetPrefix}ar rcu"
    substituteInPlace src/Makefile \
      --replace-fail "as --64 -g" "${stdenv.cc.targetPrefix}as --64 -g"
  '';

  nativeBuildInputs = [ pkg-config ];
  buildInputs = [
    jemalloc
    curl
    libuuid
  ] ++ lib.optionals tlsSupport [ openssl ] ++ lib.optionals withSystemd [ systemd ];

  makeFlags =
    [
      "PREFIX=${placeholder "out"}"
      "AR=${stdenv.cc.targetPrefix}ar"
      "RANLIB=${stdenv.cc.targetPrefix}ranlib"
      "USEASM=${if stdenv.isx86_64 then "true" else "false"}"
    ]
    ++ lib.optionals (!tlsSupport) [ "BUILD_TLS=no" ]
    ++ lib.optionals withSystemd [ "USE_SYSTEMD=yes" ]
    ++ lib.optionals (!stdenv.isx86_64) [ "MALLOC=libc" ];

  enableParallelBuilding = true;

  hardeningEnable = lib.optionals (!stdenv.isDarwin) [ "pie" ];

  # darwin currently lacks a pure `pgrep` which is extensively used here
  doCheck = !stdenv.isDarwin;
  nativeCheckInputs = [
    which
    tcl
    ps
  ] ++ lib.optionals stdenv.hostPlatform.isStatic [ getconf ] ++ lib.optionals tlsSupport [ tcltls ];
  checkPhase = ''
    runHook preCheck

    # disable test "Connect multiple replicas at the same time": even
    # upstream find this test too timing-sensitive
    substituteInPlace tests/integration/replication.tcl \
      --replace-fail 'foreach mdl {no yes}' 'foreach mdl {}'

    substituteInPlace tests/support/server.tcl \
      --replace-fail 'exec /usr/bin/env' 'exec env'

    sed -i '/^proc wait_load_handlers_disconnected/{n ; s/wait_for_condition 50 100/wait_for_condition 50 500/; }' \
      tests/support/util.tcl

    patchShebangs ./utils/gen-test-certs.sh
    ${if tlsSupport then "./utils/gen-test-certs.sh" else ""}

    ./runtest \
      --no-latency \
      --timeout 2000 \
      --clients $NIX_BUILD_CORES \
      --tags -leaks ${if tlsSupport then "--tls" else ""}

    runHook postCheck
  '';

  passthru.tests.redis = nixosTests.redis;
  passthru.serverBin = "keydb-server";

  meta = with lib; {
    homepage = "https://keydb.dev";
    description = "A Multithreaded Fork of Redis";
    license = licenses.bsd3;
    platforms = platforms.all;
    changelog = "https://github.com/Snapchat/KeyDB/raw/v${version}/00-RELEASENOTES";
    maintainers = teams.helsinki-systems.members;
    mainProgram = "keydb-cli";
  };
}