1 { config, lib, pkgs, ... }:
6 cfg = config.services.zookeeper;
10 clientPort=${toString cfg.port}
11 autopurge.purgeInterval=${toString cfg.purgeInterval}
16 configDir = pkgs.buildEnv {
17 name = "zookeeper-conf";
19 (pkgs.writeTextDir "zoo.cfg" zookeeperConfig)
20 (pkgs.writeTextDir "log4j.properties" cfg.logging)
26 options.services.zookeeper = {
27 enable = mkEnableOption (lib.mdDoc "Zookeeper");
30 description = lib.mdDoc "Zookeeper Client port.";
36 description = lib.mdDoc "Zookeeper ID.";
41 purgeInterval = mkOption {
42 description = lib.mdDoc ''
43 The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging.
49 extraConf = mkOption {
50 description = lib.mdDoc "Extra configuration for Zookeeper.";
60 description = lib.mdDoc "All Zookeeper Servers.";
64 server.0=host0:2888:3888
65 server.1=host1:2888:3888
66 server.2=host2:2888:3888
71 description = lib.mdDoc "Zookeeper logging configuration.";
73 zookeeper.root.logger=INFO, CONSOLE
74 log4j.rootLogger=INFO, CONSOLE
75 log4j.logger.org.apache.zookeeper.audit.Log4jAuditLogger=INFO, CONSOLE
76 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
77 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
78 log4j.appender.CONSOLE.layout.ConversionPattern=[myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
85 default = "/var/lib/zookeeper";
86 description = lib.mdDoc ''
87 Data directory for Zookeeper
91 extraCmdLineOptions = mkOption {
92 description = lib.mdDoc "Extra command line options for the Zookeeper launcher.";
93 default = [ "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
94 type = types.listOf types.str;
95 example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
98 preferIPv4 = mkOption {
101 description = lib.mdDoc ''
102 Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
107 description = lib.mdDoc "The zookeeper package to use";
108 default = pkgs.zookeeper;
109 defaultText = literalExpression "pkgs.zookeeper";
110 type = types.package;
114 description = lib.mdDoc "The JRE with which to run Zookeeper";
115 default = cfg.package.jre;
116 defaultText = literalExpression "pkgs.zookeeper.jre";
117 example = literalExpression "pkgs.jre";
118 type = types.package;
123 config = mkIf cfg.enable {
124 environment.systemPackages = [cfg.package];
126 systemd.tmpfiles.rules = [
127 "d '${cfg.dataDir}' 0700 zookeeper - - -"
128 "Z '${cfg.dataDir}' 0700 zookeeper - - -"
131 systemd.services.zookeeper = {
132 description = "Zookeeper Daemon";
133 wantedBy = [ "multi-user.target" ];
134 after = [ "network.target" ];
137 ${cfg.jre}/bin/java \
138 -cp "${cfg.package}/lib/*:${configDir}" \
139 ${escapeShellArgs cfg.extraCmdLineOptions} \
140 -Dzookeeper.datadir.autocreate=false \
141 ${optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
142 org.apache.zookeeper.server.quorum.QuorumPeerMain \
148 echo "${toString cfg.id}" > ${cfg.dataDir}/myid
149 mkdir -p ${cfg.dataDir}/version-2
153 users.users.zookeeper = {
156 description = "Zookeeper daemon user";
159 users.groups.zookeeper = {};