From d75b01eb76f4c98423ebda6c49f6b8a08570f211 Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Thu, 12 Mar 2026 22:12:34 +0000 Subject: [PATCH] apacheKafka: Refactor into per-series files with generic.nix Split the monolithic default.nix versionMap into per-series files that import a shared generic.nix --- pkgs/servers/apache-kafka/3_9.nix | 6 ++ pkgs/servers/apache-kafka/4_0.nix | 6 ++ pkgs/servers/apache-kafka/4_1.nix | 6 ++ pkgs/servers/apache-kafka/default.nix | 106 ++------------------------ pkgs/servers/apache-kafka/generic.nix | 82 ++++++++++++++++++++ 5 files changed, 105 insertions(+), 101 deletions(-) create mode 100644 pkgs/servers/apache-kafka/3_9.nix create mode 100644 pkgs/servers/apache-kafka/4_0.nix create mode 100644 pkgs/servers/apache-kafka/4_1.nix create mode 100644 pkgs/servers/apache-kafka/generic.nix diff --git a/pkgs/servers/apache-kafka/3_9.nix b/pkgs/servers/apache-kafka/3_9.nix new file mode 100644 index 000000000000..27fa276fb09f --- /dev/null +++ b/pkgs/servers/apache-kafka/3_9.nix @@ -0,0 +1,6 @@ +import ./generic.nix { + seriesFile = ./3_9.nix; + kafkaVersion = "3.9.1"; + scalaVersion = "2.13"; + sha256 = "sha256-3UOZgW5niUbKt2470WhhA1VeabyPKrhobNpxqhW8MaM="; +} diff --git a/pkgs/servers/apache-kafka/4_0.nix b/pkgs/servers/apache-kafka/4_0.nix new file mode 100644 index 000000000000..1b87feaa230f --- /dev/null +++ b/pkgs/servers/apache-kafka/4_0.nix @@ -0,0 +1,6 @@ +import ./generic.nix { + seriesFile = ./4_0.nix; + kafkaVersion = "4.0.1"; + scalaVersion = "2.13"; + sha256 = "sha256-M8xc04WE6w9yYWxMLwX7SINKVvoKnNn+AKxzIMNM9SQ="; +} diff --git a/pkgs/servers/apache-kafka/4_1.nix b/pkgs/servers/apache-kafka/4_1.nix new file mode 100644 index 000000000000..4c226ec3d6d7 --- /dev/null +++ b/pkgs/servers/apache-kafka/4_1.nix @@ -0,0 +1,6 @@ +import ./generic.nix { + seriesFile = ./4_1.nix; + kafkaVersion = "4.1.1"; + scalaVersion = "2.13"; + sha256 = "sha256-eR6O5plpgtgFWCk2eoA5H5TBvKcymy+7ZYv8IRp3Ry4="; +} diff --git a/pkgs/servers/apache-kafka/default.nix b/pkgs/servers/apache-kafka/default.nix index d6eacbe3d130..039c829f9bbc 100644 --- a/pkgs/servers/apache-kafka/default.nix +++ b/pkgs/servers/apache-kafka/default.nix @@ -1,102 +1,6 @@ +{ callPackage }: { - lib, - stdenv, - fetchurl, - jdk17_headless, - makeWrapper, - bash, - coreutils, - gnugrep, - gnused, - ps, - nixosTests, -}: - -let - versionMap = { - "4_1" = { - kafkaVersion = "4.1.1"; - scalaVersion = "2.13"; - sha256 = "sha256-eR6O5plpgtgFWCk2eoA5H5TBvKcymy+7ZYv8IRp3Ry4="; - jre = jdk17_headless; - nixosTest = nixosTests.kafka.base.kafka_4_1; - }; - "4_0" = { - kafkaVersion = "4.0.1"; - scalaVersion = "2.13"; - sha256 = "sha256-M8xc04WE6w9yYWxMLwX7SINKVvoKnNn+AKxzIMNM9SQ="; - jre = jdk17_headless; - nixosTest = nixosTests.kafka.base.kafka_4_0; - }; - "3_9" = { - kafkaVersion = "3.9.1"; - scalaVersion = "2.13"; - sha256 = "sha256-3UOZgW5niUbKt2470WhhA1VeabyPKrhobNpxqhW8MaM="; - jre = jdk17_headless; - nixosTest = nixosTests.kafka.base.kafka_3_9; - }; - }; - - build = - versionInfo: - stdenv.mkDerivation rec { - version = "${versionInfo.scalaVersion}-${versionInfo.kafkaVersion}"; - pname = "apache-kafka"; - - src = fetchurl { - url = "mirror://apache/kafka/${versionInfo.kafkaVersion}/kafka_${version}.tgz"; - inherit (versionInfo) sha256; - }; - - nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ - versionInfo.jre - bash - gnugrep - gnused - coreutils - ps - ]; - - installPhase = '' - mkdir -p $out - cp -R config libs $out - - mkdir -p $out/bin - cp bin/kafka* $out/bin - cp bin/connect* $out/bin - - # allow us the specify logging directory using env - substituteInPlace $out/bin/kafka-run-class.sh \ - --replace 'LOG_DIR="$base_dir/logs"' 'LOG_DIR="$KAFKA_LOG_DIR"' - - substituteInPlace $out/bin/kafka-server-stop.sh \ - --replace 'ps' '${ps}/bin/ps' - - for p in $out/bin\/*.sh; do - wrapProgram $p \ - --set JAVA_HOME "${versionInfo.jre}" \ - --set KAFKA_LOG_DIR "/tmp/apache-kafka-logs" \ - --prefix PATH : "${bash}/bin:${coreutils}/bin:${gnugrep}/bin:${gnused}/bin" - done - chmod +x $out/bin\/* - ''; - - passthru = { - inherit (versionInfo) jre; # Used by the NixOS module to select the supported JRE - tests.nixos = versionInfo.nixosTest; - }; - - meta = { - homepage = "https://kafka.apache.org"; - description = "High-throughput distributed messaging system"; - license = lib.licenses.asl20; - sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; - maintainers = [ lib.maintainers.ragge ]; - platforms = lib.platforms.unix; - }; - }; -in -lib.mapAttrs' ( - majorVersion: versionInfo: lib.nameValuePair "apacheKafka_${majorVersion}" (build versionInfo) -) versionMap + apacheKafka_4_1 = callPackage ./4_1.nix { }; + apacheKafka_4_0 = callPackage ./4_0.nix { }; + apacheKafka_3_9 = callPackage ./3_9.nix { }; +} diff --git a/pkgs/servers/apache-kafka/generic.nix b/pkgs/servers/apache-kafka/generic.nix new file mode 100644 index 000000000000..1d52bd5e73d2 --- /dev/null +++ b/pkgs/servers/apache-kafka/generic.nix @@ -0,0 +1,82 @@ +{ + seriesFile, + kafkaVersion, + scalaVersion, + sha256, +}: + +{ + lib, + stdenv, + fetchurl, + jdk17_headless, + makeWrapper, + bash, + coreutils, + gnugrep, + gnused, + ps, + nixosTests, +}: + +let + jre = jdk17_headless; + series = lib.replaceStrings [ "." ] [ "_" ] (lib.versions.majorMinor kafkaVersion); +in +stdenv.mkDerivation rec { + version = "${scalaVersion}-${kafkaVersion}"; + pname = "apache-kafka"; + + src = fetchurl { + url = "mirror://apache/kafka/${kafkaVersion}/kafka_${version}.tgz"; + inherit sha256; + }; + + nativeBuildInputs = [ makeWrapper ]; + buildInputs = [ + jre + bash + gnugrep + gnused + coreutils + ps + ]; + + installPhase = '' + mkdir -p $out + cp -R config libs $out + + mkdir -p $out/bin + cp bin/kafka* $out/bin + cp bin/connect* $out/bin + + # allow us the specify logging directory using env + substituteInPlace $out/bin/kafka-run-class.sh \ + --replace 'LOG_DIR="$base_dir/logs"' 'LOG_DIR="$KAFKA_LOG_DIR"' + + substituteInPlace $out/bin/kafka-server-stop.sh \ + --replace 'ps' '${ps}/bin/ps' + + for p in $out/bin\/*.sh; do + wrapProgram $p \ + --set JAVA_HOME "${jre}" \ + --set KAFKA_LOG_DIR "/tmp/apache-kafka-logs" \ + --prefix PATH : "${bash}/bin:${coreutils}/bin:${gnugrep}/bin:${gnused}/bin" + done + chmod +x $out/bin\/* + ''; + + passthru = { + inherit jre; # Used by the NixOS module to select the supported JRE + tests.nixos = nixosTests.kafka.base.${"kafka_" + series}; + }; + + meta = { + homepage = "https://kafka.apache.org"; + description = "High-throughput distributed messaging system"; + license = lib.licenses.asl20; + sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; + maintainers = [ lib.maintainers.ragge ]; + platforms = lib.platforms.unix; + }; +}