forked from mirrors/nixpkgs
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
152 lines
4 KiB
Nix
152 lines
4 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.apache-kafka;
|
|
|
|
serverProperties =
|
|
if cfg.serverProperties != null then
|
|
cfg.serverProperties
|
|
else
|
|
''
|
|
# Generated by nixos
|
|
broker.id=${toString cfg.brokerId}
|
|
port=${toString cfg.port}
|
|
host.name=${cfg.hostname}
|
|
log.dirs=${concatStringsSep "," cfg.logDirs}
|
|
zookeeper.connect=${cfg.zookeeper}
|
|
${toString cfg.extraProperties}
|
|
'';
|
|
|
|
serverConfig = pkgs.writeText "server.properties" serverProperties;
|
|
logConfig = pkgs.writeText "log4j.properties" cfg.log4jProperties;
|
|
|
|
in {
|
|
|
|
options.services.apache-kafka = {
|
|
enable = mkOption {
|
|
description = lib.mdDoc "Whether to enable Apache Kafka.";
|
|
default = false;
|
|
type = types.bool;
|
|
};
|
|
|
|
brokerId = mkOption {
|
|
description = lib.mdDoc "Broker ID.";
|
|
default = -1;
|
|
type = types.int;
|
|
};
|
|
|
|
port = mkOption {
|
|
description = lib.mdDoc "Port number the broker should listen on.";
|
|
default = 9092;
|
|
type = types.int;
|
|
};
|
|
|
|
hostname = mkOption {
|
|
description = lib.mdDoc "Hostname the broker should bind to.";
|
|
default = "localhost";
|
|
type = types.str;
|
|
};
|
|
|
|
logDirs = mkOption {
|
|
description = lib.mdDoc "Log file directories";
|
|
default = [ "/tmp/kafka-logs" ];
|
|
type = types.listOf types.path;
|
|
};
|
|
|
|
zookeeper = mkOption {
|
|
description = lib.mdDoc "Zookeeper connection string";
|
|
default = "localhost:2181";
|
|
type = types.str;
|
|
};
|
|
|
|
extraProperties = mkOption {
|
|
description = lib.mdDoc "Extra properties for server.properties.";
|
|
type = types.nullOr types.lines;
|
|
default = null;
|
|
};
|
|
|
|
serverProperties = mkOption {
|
|
description = lib.mdDoc ''
|
|
Complete server.properties content. Other server.properties config
|
|
options will be ignored if this option is used.
|
|
'';
|
|
type = types.nullOr types.lines;
|
|
default = null;
|
|
};
|
|
|
|
log4jProperties = mkOption {
|
|
description = lib.mdDoc "Kafka log4j property configuration.";
|
|
default = ''
|
|
log4j.rootLogger=INFO, stdout
|
|
|
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
|
|
'';
|
|
type = types.lines;
|
|
};
|
|
|
|
jvmOptions = mkOption {
|
|
description = lib.mdDoc "Extra command line options for the JVM running Kafka.";
|
|
default = [];
|
|
type = types.listOf types.str;
|
|
example = [
|
|
"-Djava.net.preferIPv4Stack=true"
|
|
"-Dcom.sun.management.jmxremote"
|
|
"-Dcom.sun.management.jmxremote.local.only=true"
|
|
];
|
|
};
|
|
|
|
package = mkOption {
|
|
description = lib.mdDoc "The kafka package to use";
|
|
default = pkgs.apacheKafka;
|
|
defaultText = literalExpression "pkgs.apacheKafka";
|
|
type = types.package;
|
|
};
|
|
|
|
jre = mkOption {
|
|
description = lib.mdDoc "The JRE with which to run Kafka";
|
|
default = cfg.package.passthru.jre;
|
|
defaultText = literalExpression "pkgs.apacheKafka.passthru.jre";
|
|
type = types.package;
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [cfg.package];
|
|
|
|
users.users.apache-kafka = {
|
|
isSystemUser = true;
|
|
group = "apache-kafka";
|
|
description = "Apache Kafka daemon user";
|
|
home = head cfg.logDirs;
|
|
};
|
|
users.groups.apache-kafka = {};
|
|
|
|
systemd.tmpfiles.rules = map (logDir: "d '${logDir}' 0700 apache-kafka - - -") cfg.logDirs;
|
|
|
|
systemd.services.apache-kafka = {
|
|
description = "Apache Kafka Daemon";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network.target" ];
|
|
serviceConfig = {
|
|
ExecStart = ''
|
|
${cfg.jre}/bin/java \
|
|
-cp "${cfg.package}/libs/*" \
|
|
-Dlog4j.configuration=file:${logConfig} \
|
|
${toString cfg.jvmOptions} \
|
|
kafka.Kafka \
|
|
${serverConfig}
|
|
'';
|
|
User = "apache-kafka";
|
|
SuccessExitStatus = "0 143";
|
|
};
|
|
};
|
|
|
|
};
|
|
}
|