From 62e1675246f51da517e076da7272ded3fe4bea2d Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 24 Aug 2024 22:05:38 +0200 Subject: [PATCH] nixos/services.apache-kafka: remove `with lib;` --- nixos/modules/services/misc/apache-kafka.nix | 89 ++++++++++---------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/nixos/modules/services/misc/apache-kafka.nix b/nixos/modules/services/misc/apache-kafka.nix index d1a3d92f2e22..0ed20961c57b 100644 --- a/nixos/modules/services/misc/apache-kafka.nix +++ b/nixos/modules/services/misc/apache-kafka.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.services.apache-kafka; @@ -17,24 +14,24 @@ let mkPropertyString = let render = { - bool = boolToString; + bool = lib.boolToString; int = toString; - list = concatMapStringsSep "," mkPropertyString; - string = id; + list = lib.concatMapStringsSep "," mkPropertyString; + string = lib.id; }; in v: render.${builtins.typeOf v} v; - stringlySettings = mapAttrs (_: mkPropertyString) - (filterAttrs (_: v: v != null) cfg.settings); + stringlySettings = lib.mapAttrs (_: mkPropertyString) + (lib.filterAttrs (_: v: v != null) cfg.settings); generator = (pkgs.formats.javaProperties {}).generate; in { options.services.apache-kafka = { - enable = mkEnableOption "Apache Kafka event streaming broker"; + enable = lib.mkEnableOption "Apache Kafka event streaming broker"; - settings = mkOption { + settings = lib.mkOption { description = '' [Kafka broker configuration](https://kafka.apache.org/documentation.html#brokerconfigs) {file}`server.properties`. @@ -44,81 +41,81 @@ in { but instead as quoted strings (ie. `settings."broker.id"`, NOT `settings.broker.id`). ''; - type = types.submodule { - freeformType = with types; let + type = lib.types.submodule { + freeformType = with lib.types; let primitive = oneOf [bool int str]; in lazyAttrsOf (nullOr (either primitive (listOf primitive))); options = { - "broker.id" = mkOption { + "broker.id" = lib.mkOption { description = "Broker ID. -1 or null to auto-allocate in zookeeper mode."; default = null; - type = with types; nullOr int; + type = with lib.types; nullOr int; }; - "log.dirs" = mkOption { + "log.dirs" = lib.mkOption { description = "Log file directories."; # Deliberaly leave out old default and use the rewrite opportunity # to have users choose a safer value -- /tmp might be volatile and is a # slightly scary default choice. # default = [ "/tmp/apache-kafka" ]; - type = with types; listOf path; + type = with lib.types; listOf path; }; - "listeners" = mkOption { + "listeners" = lib.mkOption { description = '' Kafka Listener List. See [listeners](https://kafka.apache.org/documentation/#brokerconfigs_listeners). ''; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; default = [ "PLAINTEXT://localhost:9092" ]; }; }; }; }; - clusterId = mkOption { + clusterId = lib.mkOption { description = '' KRaft mode ClusterId used for formatting log directories. Can be generated with `kafka-storage.sh random-uuid` ''; - type = with types; nullOr str; + type = with lib.types; nullOr str; default = null; }; - configFiles.serverProperties = mkOption { + configFiles.serverProperties = lib.mkOption { description = '' Kafka server.properties configuration file path. Defaults to the rendered `settings`. ''; - type = types.path; + type = lib.types.path; }; - configFiles.log4jProperties = mkOption { + configFiles.log4jProperties = lib.mkOption { description = "Kafka log4j property configuration file path"; - type = types.path; + type = lib.types.path; default = pkgs.writeText "log4j.properties" cfg.log4jProperties; defaultText = ''pkgs.writeText "log4j.properties" cfg.log4jProperties''; }; - formatLogDirs = mkOption { + formatLogDirs = lib.mkOption { description = '' Whether to format log dirs in KRaft mode if all log dirs are unformatted, ie. they contain no meta.properties. ''; - type = types.bool; + type = lib.types.bool; default = false; }; - formatLogDirsIgnoreFormatted = mkOption { + formatLogDirsIgnoreFormatted = lib.mkOption { description = '' Whether to ignore already formatted log dirs when formatting log dirs, instead of failing. Useful when replacing or adding disks. ''; - type = types.bool; + type = lib.types.bool; default = false; }; - log4jProperties = mkOption { + log4jProperties = lib.mkOption { description = "Kafka log4j property configuration."; default = '' log4j.rootLogger=INFO, stdout @@ -127,13 +124,13 @@ in { log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n ''; - type = types.lines; + type = lib.types.lines; }; - jvmOptions = mkOption { + jvmOptions = lib.mkOption { description = "Extra command line options for the JVM running Kafka."; default = []; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" @@ -141,38 +138,38 @@ in { ]; }; - package = mkPackageOption pkgs "apacheKafka" { }; + package = lib.mkPackageOption pkgs "apacheKafka" { }; - jre = mkOption { + jre = lib.mkOption { description = "The JRE with which to run Kafka"; default = cfg.package.passthru.jre; - defaultText = literalExpression "pkgs.apacheKafka.passthru.jre"; - type = types.package; + defaultText = lib.literalExpression "pkgs.apacheKafka.passthru.jre"; + type = lib.types.package; }; }; imports = [ - (mkRenamedOptionModule + (lib.mkRenamedOptionModule [ "services" "apache-kafka" "brokerId" ] [ "services" "apache-kafka" "settings" ''broker.id'' ]) - (mkRenamedOptionModule + (lib.mkRenamedOptionModule [ "services" "apache-kafka" "logDirs" ] [ "services" "apache-kafka" "settings" ''log.dirs'' ]) - (mkRenamedOptionModule + (lib.mkRenamedOptionModule [ "services" "apache-kafka" "zookeeper" ] [ "services" "apache-kafka" "settings" ''zookeeper.connect'' ]) - (mkRemovedOptionModule [ "services" "apache-kafka" "port" ] + (lib.mkRemovedOptionModule [ "services" "apache-kafka" "port" ] "Please see services.apache-kafka.settings.listeners and its documentation instead") - (mkRemovedOptionModule [ "services" "apache-kafka" "hostname" ] + (lib.mkRemovedOptionModule [ "services" "apache-kafka" "hostname" ] "Please see services.apache-kafka.settings.listeners and its documentation instead") - (mkRemovedOptionModule [ "services" "apache-kafka" "extraProperties" ] + (lib.mkRemovedOptionModule [ "services" "apache-kafka" "extraProperties" ] "Please see services.apache-kafka.settings and its documentation instead") - (mkRemovedOptionModule [ "services" "apache-kafka" "serverProperties" ] + (lib.mkRemovedOptionModule [ "services" "apache-kafka" "serverProperties" ] "Please see services.apache-kafka.settings and its documentation instead") ]; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { services.apache-kafka.configFiles.serverProperties = generator "server.properties" stringlySettings; users.users.apache-kafka = { @@ -188,11 +185,11 @@ in { description = "Apache Kafka Daemon"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; - preStart = mkIf cfg.formatLogDirs + preStart = lib.mkIf cfg.formatLogDirs (if cfg.formatLogDirsIgnoreFormatted then '' ${cfg.package}/bin/kafka-storage.sh format -t "${cfg.clusterId}" -c ${cfg.configFiles.serverProperties} --ignore-formatted '' else '' - if ${concatMapStringsSep " && " (l: ''[ ! -f "${l}/meta.properties" ]'') cfg.settings."log.dirs"}; then + if ${lib.concatMapStringsSep " && " (l: ''[ ! -f "${l}/meta.properties" ]'') cfg.settings."log.dirs"}; then ${cfg.package}/bin/kafka-storage.sh format -t "${cfg.clusterId}" -c ${cfg.configFiles.serverProperties} fi '');