nixos/services.zookeeper: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:46:53 +02:00
parent f8b0d3a756
commit 59a4e8349e

View File

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.zookeeper;
@ -24,31 +21,31 @@ let
in {
options.services.zookeeper = {
enable = mkEnableOption "Zookeeper";
enable = lib.mkEnableOption "Zookeeper";
port = mkOption {
port = lib.mkOption {
description = "Zookeeper Client port.";
default = 2181;
type = types.port;
type = lib.types.port;
};
id = mkOption {
id = lib.mkOption {
description = "Zookeeper ID.";
default = 0;
type = types.int;
type = lib.types.int;
};
purgeInterval = mkOption {
purgeInterval = lib.mkOption {
description = ''
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.
'';
default = 1;
type = types.int;
type = lib.types.int;
};
extraConf = mkOption {
extraConf = lib.mkOption {
description = "Extra configuration for Zookeeper.";
type = types.lines;
type = lib.types.lines;
default = ''
initLimit=5
syncLimit=2
@ -56,10 +53,10 @@ in {
'';
};
servers = mkOption {
servers = lib.mkOption {
description = "All Zookeeper Servers.";
default = "";
type = types.lines;
type = lib.types.lines;
example = ''
server.0=host0:2888:3888
server.1=host1:2888:3888
@ -67,7 +64,7 @@ in {
'';
};
logging = mkOption {
logging = lib.mkOption {
description = "Zookeeper logging configuration.";
default = ''
zookeeper.root.logger=INFO, CONSOLE
@ -77,45 +74,45 @@ in {
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
'';
type = types.lines;
type = lib.types.lines;
};
dataDir = mkOption {
type = types.path;
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/zookeeper";
description = ''
Data directory for Zookeeper
'';
};
extraCmdLineOptions = mkOption {
extraCmdLineOptions = lib.mkOption {
description = "Extra command line options for the Zookeeper launcher.";
default = [ "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
type = types.listOf types.str;
type = lib.types.listOf lib.types.str;
example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
};
preferIPv4 = mkOption {
type = types.bool;
preferIPv4 = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
'';
};
package = mkPackageOption pkgs "zookeeper" { };
package = lib.mkPackageOption pkgs "zookeeper" { };
jre = mkOption {
jre = lib.mkOption {
description = "The JRE with which to run Zookeeper";
default = cfg.package.jre;
defaultText = literalExpression "pkgs.zookeeper.jre";
example = literalExpression "pkgs.jre";
type = types.package;
defaultText = lib.literalExpression "pkgs.zookeeper.jre";
example = lib.literalExpression "pkgs.jre";
type = lib.types.package;
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
environment.systemPackages = [cfg.package];
systemd.tmpfiles.rules = [
@ -131,9 +128,9 @@ in {
ExecStart = ''
${cfg.jre}/bin/java \
-cp "${cfg.package}/lib/*:${configDir}" \
${escapeShellArgs cfg.extraCmdLineOptions} \
${lib.escapeShellArgs cfg.extraCmdLineOptions} \
-Dzookeeper.datadir.autocreate=false \
${optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
${lib.optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
org.apache.zookeeper.server.quorum.QuorumPeerMain \
${configDir}/zoo.cfg
'';