summary refs log tree commit diff
diff options
context:
space:
mode:
authorYureka <yuka@yuka.dev>2023-07-15 20:02:13 +0200
committerGitHub <noreply@github.com>2023-07-15 13:02:13 -0500
commite16a75d3be094fe120724e49b53adf64e684ef2c (patch)
treee92a11a4ce040ce9c1292c84eb82cae47679212d
parent42066dc04df8cb9cf92ccec33d80b233237806e9 (diff)
downloadnixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar.gz
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar.bz2
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar.lz
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar.xz
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.tar.zst
nixpkgs-e16a75d3be094fe120724e49b53adf64e684ef2c.zip
redis: use system jemalloc (#243398)
* redis: use system jemalloc
-rw-r--r--nixos/doc/manual/release-notes/rl-2111.section.md2
-rw-r--r--pkgs/servers/nosql/redis/default.nix21
2 files changed, 17 insertions, 6 deletions
diff --git a/nixos/doc/manual/release-notes/rl-2111.section.md b/nixos/doc/manual/release-notes/rl-2111.section.md
index 159881a0ac4..400eb1062d9 100644
--- a/nixos/doc/manual/release-notes/rl-2111.section.md
+++ b/nixos/doc/manual/release-notes/rl-2111.section.md
@@ -441,6 +441,8 @@ In addition to numerous new and upgraded packages, this release has the followin
 
 - `pkgs.haskell-language-server` will now by default be linked dynamically to improve TemplateHaskell compatibility. To mitigate the increased closure size it will now by default only support our current default ghc (at the moment 9.0.2). Add other ghc versions via e.g. `pkgs.haskell-language-server.override { supportedGhcVersions = [ "90" "92" ]; }`.
 
+- `pkgs.redis` is now built using the system jemalloc. This disables the experimental active defragmentation feature of redis. Users who require this feature can switch back to redis' vendored version of jemalloc by setting `services.redis.package = pkgs.redis.override { useSystemJemalloc = false; };`.
+
 ## Other Notable Changes {#sec-release-21.11-notable-changes}
 
 
diff --git a/pkgs/servers/nosql/redis/default.nix b/pkgs/servers/nosql/redis/default.nix
index b71bbf52d8e..00d181b6b49 100644
--- a/pkgs/servers/nosql/redis/default.nix
+++ b/pkgs/servers/nosql/redis/default.nix
@@ -1,8 +1,13 @@
-{ lib, stdenv, fetchurl, fetchpatch, lua, pkg-config, nixosTests
+{ lib, stdenv, fetchurl, fetchpatch, lua, jemalloc, pkg-config, nixosTests
 , tcl, which, ps, getconf
 , withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, systemd
 # dependency ordering is broken at the moment when building with openssl
 , tlsSupport ? !stdenv.hostPlatform.isStatic, openssl
+
+# Using system jemalloc fixes cross-compilation and various setups.
+# However the experimental 'active defragmentation' feature of redis requires
+# their custom patched version of jemalloc.
+, useSystemJemalloc ? true
 }:
 
 stdenv.mkDerivation rec {
@@ -20,19 +25,23 @@ stdenv.mkDerivation rec {
       url = "https://github.com/redis/redis/commit/bfe50a30edff6837897964ac3374c082b0d9e5da.patch";
       sha256 = "sha256-0GMiygbO7LbL1rnuOByOJYE2BKUSI+yy6YH781E2zBw=";
     })
-  ];
+  ] ++ lib.optional useSystemJemalloc
+    # use system jemalloc
+    (fetchurl {
+      url = "https://gitlab.archlinux.org/archlinux/packaging/packages/redis/-/raw/102cc861713c796756abd541bf341a4512eb06e6/redis-5.0-use-system-jemalloc.patch";
+      hash = "sha256-VPRfoSnctkkkzLrXEWQX3Lh5HmZaCXoJafyOG007KzM=";
+    })
+  ;
 
   nativeBuildInputs = [ pkg-config ];
 
   buildInputs = [ lua ]
+    ++ lib.optional useSystemJemalloc jemalloc
     ++ lib.optional withSystemd systemd
     ++ lib.optionals tlsSupport [ openssl ];
   # More cross-compiling fixes.
-  # Note: this enables libc malloc as a temporary fix for cross-compiling.
-  # Due to hardcoded configure flags in jemalloc, we can't cross-compile vendored jemalloc properly, and so we're forced to use libc allocator.
-  # It's weird that the build isn't failing because of failure to compile dependencies, it's from failure to link them!
   makeFlags = [ "PREFIX=${placeholder "out"}" ]
-    ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "AR=${stdenv.cc.targetPrefix}ar" "RANLIB=${stdenv.cc.targetPrefix}ranlib" "MALLOC=libc" ]
+    ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "AR=${stdenv.cc.targetPrefix}ar" "RANLIB=${stdenv.cc.targetPrefix}ranlib" ]
     ++ lib.optionals withSystemd [ "USE_SYSTEMD=yes" ]
     ++ lib.optionals tlsSupport [ "BUILD_TLS=yes" ];