nixos/mastodon: update redis host and port configurations

This commit is contained in:
Izorkin 2024-02-17 20:46:55 +03:00
parent 3cf52f6b0b
commit a05afb1437
No known key found for this signature in database
GPG Key ID: 1436C1B3F3679F09

View File

@ -20,8 +20,6 @@ let
DB_USER = cfg.database.user; DB_USER = cfg.database.user;
REDIS_HOST = cfg.redis.host;
REDIS_PORT = toString(cfg.redis.port);
DB_HOST = cfg.database.host; DB_HOST = cfg.database.host;
DB_NAME = cfg.database.name; DB_NAME = cfg.database.name;
LOCAL_DOMAIN = cfg.localDomain; LOCAL_DOMAIN = cfg.localDomain;
@ -34,6 +32,8 @@ let
TRUSTED_PROXY_IP = cfg.trustedProxy; TRUSTED_PROXY_IP = cfg.trustedProxy;
} }
// lib.optionalAttrs (cfg.redis.host != null) { REDIS_HOST = cfg.redis.host; }
// lib.optionalAttrs (cfg.redis.port != null) { REDIS_PORT = toString(cfg.redis.port); }
// lib.optionalAttrs (cfg.redis.createLocally && cfg.redis.enableUnixSocket) { REDIS_URL = "unix://${config.services.redis.servers.mastodon.unixSocket}"; } // lib.optionalAttrs (cfg.redis.createLocally && cfg.redis.enableUnixSocket) { REDIS_URL = "unix://${config.services.redis.servers.mastodon.unixSocket}"; }
// lib.optionalAttrs (cfg.database.host != "/run/postgresql" && cfg.database.port != null) { DB_PORT = toString cfg.database.port; } // lib.optionalAttrs (cfg.database.host != "/run/postgresql" && cfg.database.port != null) { DB_PORT = toString cfg.database.port; }
// lib.optionalAttrs cfg.smtp.authenticate { SMTP_LOGIN = cfg.smtp.user; } // lib.optionalAttrs cfg.smtp.authenticate { SMTP_LOGIN = cfg.smtp.user; }
@ -401,14 +401,20 @@ in {
host = lib.mkOption { host = lib.mkOption {
description = "Redis host."; description = "Redis host.";
type = lib.types.str; type = lib.types.nullOr lib.types.str;
default = "127.0.0.1"; default = if cfg.redis.createLocally && !cfg.redis.enableUnixSocket then "127.0.0.1" else null;
defaultText = lib.literalExpression ''
if config.${opt.redis.createLocally} && !config.${opt.redis.enableUnixSocket} then "127.0.0.1" else null
'';
}; };
port = lib.mkOption { port = lib.mkOption {
description = "Redis port."; description = "Redis port.";
type = lib.types.port; type = lib.types.nullOr lib.types.port;
default = 31637; default = if cfg.redis.createLocally && !cfg.redis.enableUnixSocket then 31637 else null;
defaultText = lib.literalExpression ''
if config.${opt.redis.createLocally} && !config.${opt.redis.enableUnixSocket} then 31637 else null
'';
}; };
passwordFile = lib.mkOption { passwordFile = lib.mkOption {
@ -631,6 +637,20 @@ in {
config = lib.mkIf cfg.enable (lib.mkMerge [{ config = lib.mkIf cfg.enable (lib.mkMerge [{
assertions = [ assertions = [
{
assertion = !redisActuallyCreateLocally -> (cfg.redis.host != "127.0.0.1" && cfg.redis.port != null);
message = ''
`services.mastodon.redis.host` and `services.mastodon.redis.port` need to be set if
`services.mastodon.redis.createLocally` is not enabled.
'';
}
{
assertion = redisActuallyCreateLocally -> (!cfg.redis.enableUnixSocket || (cfg.redis.host == null && cfg.redis.port == null));
message = ''
`services.mastodon.redis.enableUnixSocket` needs to be disabled if
`services.mastodon.redis.host` and `services.mastodon.redis.port` is used.
'';
}
{ {
assertion = redisActuallyCreateLocally -> (!cfg.redis.enableUnixSocket || cfg.redis.passwordFile == null); assertion = redisActuallyCreateLocally -> (!cfg.redis.enableUnixSocket || cfg.redis.passwordFile == null);
message = '' message = ''