From 2d4f871b1a9532b71fc8e926de3e9cd22148b5f9 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 27 Aug 2024 20:42:53 +0200 Subject: [PATCH] nixos/services.rabbitmq: remove `with lib;` --- nixos/modules/services/amqp/rabbitmq.nix | 67 +++++++++++------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/nixos/modules/services/amqp/rabbitmq.nix b/nixos/modules/services/amqp/rabbitmq.nix index b5aebaaf1275..fba26591e0ba 100644 --- a/nixos/modules/services/amqp/rabbitmq.nix +++ b/nixos/modules/services/amqp/rabbitmq.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.services.rabbitmq; @@ -16,7 +13,7 @@ in { imports = [ - (mkRemovedOptionModule [ "services" "rabbitmq" "cookie" ] '' + (lib.mkRemovedOptionModule [ "services" "rabbitmq" "cookie" ] '' This option wrote the Erlang cookie to the store, while it should be kept secret. Please remove it from your NixOS configuration and deploy a cookie securely instead. The renamed `unsafeCookie` must ONLY be used in isolated non-production environments such as NixOS VM tests. @@ -26,8 +23,8 @@ in ###### interface options = { services.rabbitmq = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to enable the RabbitMQ server, an Advanced Message @@ -35,9 +32,9 @@ in ''; }; - package = mkPackageOption pkgs "rabbitmq-server" { }; + package = lib.mkPackageOption pkgs "rabbitmq-server" { }; - listenAddress = mkOption { + listenAddress = lib.mkOption { default = "127.0.0.1"; example = ""; description = '' @@ -52,28 +49,28 @@ in configItems."listeners.tcp.1" and it's left for backwards compatibility with previous version of this module. ''; - type = types.str; + type = lib.types.str; }; - port = mkOption { + port = lib.mkOption { default = 5672; description = '' Port on which RabbitMQ will listen for AMQP connections. ''; - type = types.port; + type = lib.types.port; }; - dataDir = mkOption { - type = types.path; + dataDir = lib.mkOption { + type = lib.types.path; default = "/var/lib/rabbitmq"; description = '' Data directory for rabbitmq. ''; }; - unsafeCookie = mkOption { + unsafeCookie = lib.mkOption { default = ""; - type = types.str; + type = lib.types.str; description = '' Erlang cookie is a string of arbitrary length which must be the same for several nodes to be allowed to communicate. @@ -86,10 +83,10 @@ in ''; }; - configItems = mkOption { + configItems = lib.mkOption { default = { }; - type = types.attrsOf types.str; - example = literalExpression '' + type = lib.types.attrsOf lib.types.str; + example = lib.literalExpression '' { "auth_backends.1.authn" = "rabbit_auth_backend_ldap"; "auth_backends.1.authz" = "rabbit_auth_backend_internal"; @@ -112,9 +109,9 @@ in ''; }; - config = mkOption { + config = lib.mkOption { default = ""; - type = types.str; + type = lib.types.str; description = '' Verbatim advanced configuration file contents using the Erlang syntax. This is also known as the `advanced.config` file or the old config format. @@ -130,23 +127,23 @@ in ''; }; - plugins = mkOption { + plugins = lib.mkOption { default = [ ]; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; description = "The names of plugins to enable"; }; - pluginDirs = mkOption { + pluginDirs = lib.mkOption { default = [ ]; - type = types.listOf types.path; + type = lib.types.listOf lib.types.path; description = "The list of directories containing external plugins"; }; managementPlugin = { - enable = mkEnableOption "the management plugin"; - port = mkOption { + enable = lib.mkEnableOption "the management plugin"; + port = lib.mkOption { default = 15672; - type = types.port; + type = lib.types.port; description = '' On which port to run the management plugin ''; @@ -157,7 +154,7 @@ in ###### implementation - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { # This is needed so we will have 'rabbitmqctl' in our PATH environment.systemPackages = [ cfg.package ]; @@ -175,13 +172,13 @@ in users.groups.rabbitmq.gid = config.ids.gids.rabbitmq; services.rabbitmq.configItems = { - "listeners.tcp.1" = mkDefault "${cfg.listenAddress}:${toString cfg.port}"; - } // optionalAttrs cfg.managementPlugin.enable { + "listeners.tcp.1" = lib.mkDefault "${cfg.listenAddress}:${toString cfg.port}"; + } // lib.optionalAttrs cfg.managementPlugin.enable { "management.tcp.port" = toString cfg.managementPlugin.port; "management.tcp.ip" = cfg.listenAddress; }; - services.rabbitmq.plugins = optional cfg.managementPlugin.enable "rabbitmq_management"; + services.rabbitmq.plugins = lib.optional cfg.managementPlugin.enable "rabbitmq_management"; systemd.services.rabbitmq = { description = "RabbitMQ Server"; @@ -200,11 +197,11 @@ in RABBITMQ_LOGS = "-"; SYS_PREFIX = ""; RABBITMQ_CONFIG_FILE = config_file; - RABBITMQ_PLUGINS_DIR = concatStringsSep ":" cfg.pluginDirs; + RABBITMQ_PLUGINS_DIR = lib.concatStringsSep ":" cfg.pluginDirs; RABBITMQ_ENABLED_PLUGINS_FILE = pkgs.writeText "enabled_plugins" '' - [ ${concatStringsSep "," cfg.plugins} ]. + [ ${lib.concatStringsSep "," cfg.plugins} ]. ''; - } // optionalAttrs (cfg.config != "") { RABBITMQ_ADVANCED_CONFIG_FILE = advanced_config_file; }; + } // lib.optionalAttrs (cfg.config != "") { RABBITMQ_ADVANCED_CONFIG_FILE = advanced_config_file; }; serviceConfig = { ExecStart = "${cfg.package}/sbin/rabbitmq-server"; @@ -223,7 +220,7 @@ in }; preStart = '' - ${optionalString (cfg.unsafeCookie != "") '' + ${lib.optionalString (cfg.unsafeCookie != "") '' install -m 600 <(echo -n ${cfg.unsafeCookie}) ${cfg.dataDir}/.erlang.cookie ''} '';