1{ lib, stdenv, fetchurl, jdk17_headless, jdk11_headless, makeWrapper, bash, coreutils, gnugrep, gnused, ps,
2 majorVersion ? "1.0" }:
3
4let
5 versionMap = {
6 "3.3" = {
7 kafkaVersion = "3.3.1";
8 scalaVersion = "2.13";
9 sha256 = "sha256-GK2KNl+xEd4knTu4vzyWzRrwYOyPs+PR/Ep64Q2QQt4=";
10 jre = jdk17_headless;
11 };
12 "3.2" = {
13 kafkaVersion = "3.2.3";
14 scalaVersion = "2.13";
15 sha256 = "sha256-tvkbwBP83M1zl31J4g6uu4/LEhqJoIA9Eam48fyT24A=";
16 jre = jdk17_headless;
17 };
18 "3.1" = {
19 kafkaVersion = "3.1.2";
20 scalaVersion = "2.13";
21 sha256 = "sha256-SO1bTQkG3YQSv657QjwBeBCWbDlDqS3E5eUp7ciojnI=";
22 jre = jdk17_headless;
23 };
24 "3.0" = {
25 kafkaVersion = "3.0.2";
26 scalaVersion = "2.13";
27 sha256 = "sha256-G8b6STGlwow+iDqMCeZkF3HTKd94TKccmyfZ7AT/7yE=";
28 jre = jdk17_headless;
29 };
30 "2.8" = {
31 kafkaVersion = "2.8.2";
32 scalaVersion = "2.13";
33 sha256 = "sha256-inZXZJSs8ivtEqF6E/ApoyUHn8vg38wUG3KhowP8mfQ=";
34 jre = jdk11_headless;
35 };
36
37 };
38in
39
40with versionMap.${majorVersion};
41
42stdenv.mkDerivation rec {
43 version = "${scalaVersion}-${kafkaVersion}";
44 pname = "apache-kafka";
45
46 src = fetchurl {
47 url = "mirror://apache/kafka/${kafkaVersion}/kafka_${version}.tgz";
48 inherit sha256;
49 };
50
51 nativeBuildInputs = [ makeWrapper ];
52 buildInputs = [ jre bash gnugrep gnused coreutils ps ];
53
54 installPhase = ''
55 mkdir -p $out
56 cp -R config libs $out
57
58 mkdir -p $out/bin
59 cp bin/kafka* $out/bin
60 cp bin/connect* $out/bin
61
62 # allow us the specify logging directory using env
63 substituteInPlace $out/bin/kafka-run-class.sh \
64 --replace 'LOG_DIR="$base_dir/logs"' 'LOG_DIR="$KAFKA_LOG_DIR"'
65
66 substituteInPlace $out/bin/kafka-server-stop.sh \
67 --replace 'ps' '${ps}/bin/ps'
68
69 for p in $out/bin\/*.sh; do
70 wrapProgram $p \
71 --set JAVA_HOME "${jre}" \
72 --set KAFKA_LOG_DIR "/tmp/apache-kafka-logs" \
73 --prefix PATH : "${bash}/bin:${coreutils}/bin:${gnugrep}/bin:${gnused}/bin"
74 done
75 chmod +x $out/bin\/*
76 '';
77
78 passthru = {
79 inherit jre; # Used by the NixOS module to select the supported jre
80 };
81
82 meta = with lib; {
83 homepage = "https://kafka.apache.org";
84 description = "A high-throughput distributed messaging system";
85 license = licenses.asl20;
86 sourceProvenance = with sourceTypes; [ binaryBytecode ];
87 maintainers = [ maintainers.ragge ];
88 platforms = platforms.unix;
89 };
90}