Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchFromGitea, 5 fetchurl, 6 lua, 7 jemalloc, 8 pkg-config, 9 tcl, 10 which, 11 ps, 12 getconf, 13 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, 14 systemd, 15 # dependency ordering is broken at the moment when building with openssl 16 tlsSupport ? !stdenv.hostPlatform.isStatic, 17 openssl, 18 19 # Using system jemalloc fixes cross-compilation and various setups. 20 # However the experimental 'active defragmentation' feature of redict requires 21 # their custom patched version of jemalloc. 22 useSystemJemalloc ? true, 23}: 24 25stdenv.mkDerivation (finalAttrs: { 26 pname = "redict"; 27 version = "7.3.2"; 28 29 src = fetchFromGitea { 30 domain = "codeberg.org"; 31 owner = "redict"; 32 repo = "redict"; 33 rev = finalAttrs.version; 34 hash = "sha256-MY4OWoYQ4a5efqcUTN6lNL/kd1VrJ/OBqKw27cQ5WC8="; 35 }; 36 37 patches = lib.optionals useSystemJemalloc [ 38 # use system jemalloc 39 (fetchurl { 40 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/redis/-/raw/102cc861713c796756abd541bf341a4512eb06e6/redis-5.0-use-system-jemalloc.patch"; 41 hash = "sha256-VPRfoSnctkkkzLrXEWQX3Lh5HmZaCXoJafyOG007KzM="; 42 }) 43 ]; 44 45 nativeBuildInputs = [ pkg-config ]; 46 47 buildInputs = [ 48 lua 49 ] 50 ++ lib.optional useSystemJemalloc jemalloc 51 ++ lib.optional withSystemd systemd 52 ++ lib.optionals tlsSupport [ openssl ]; 53 54 preBuild = lib.optionalString stdenv.hostPlatform.isDarwin '' 55 substituteInPlace src/Makefile --replace-fail "-flto" "" 56 ''; 57 58 # More cross-compiling fixes. 59 makeFlags = [ 60 "PREFIX=${placeholder "out"}" 61 ] 62 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ 63 "AR=${stdenv.cc.targetPrefix}ar" 64 "RANLIB=${stdenv.cc.targetPrefix}ranlib" 65 ] 66 ++ lib.optionals withSystemd [ "USE_SYSTEMD=yes" ] 67 ++ lib.optionals tlsSupport [ "BUILD_TLS=yes" ]; 68 69 enableParallelBuilding = true; 70 71 hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ]; 72 73 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [ "-std=c11" ]); 74 75 # darwin currently lacks a pure `pgrep` which is extensively used here 76 doCheck = !stdenv.hostPlatform.isDarwin; 77 78 nativeCheckInputs = [ 79 which 80 tcl 81 ps 82 ] 83 ++ lib.optionals stdenv.hostPlatform.isStatic [ getconf ]; 84 85 checkPhase = '' 86 runHook preCheck 87 88 # disable test "Connect multiple replicas at the same time": even 89 # upstream find this test too timing-sensitive 90 substituteInPlace tests/integration/replication.tcl \ 91 --replace-fail "foreach mdl {no yes}" "foreach mdl {}" 92 93 substituteInPlace tests/support/server.tcl \ 94 --replace-fail "exec /usr/bin/env" "exec env" 95 96 sed -i '/^proc wait_load_handlers_disconnected/{n ; s/wait_for_condition 50 100/wait_for_condition 50 500/; }' \ 97 tests/support/util.tcl 98 99 ./runtest \ 100 --no-latency \ 101 --timeout 2000 \ 102 --clients $NIX_BUILD_CORES \ 103 --tags -leaks \ 104 --skipunit integration/failover # flaky and slow 105 106 runHook postCheck 107 ''; 108 109 meta = { 110 homepage = "https://redict.io"; 111 description = "Distributed key/value store"; 112 license = lib.licenses.lgpl3Only; 113 platforms = lib.platforms.all; 114 changelog = "https://codeberg.org/redict/redict/releases/tag/${finalAttrs.version}"; 115 maintainers = with lib.maintainers; [ yuka ]; 116 mainProgram = "redict-cli"; 117 }; 118})