Unverified Commit 5c01128e authored by Kerstin's avatar Kerstin Committed by GitHub
Browse files

Merge pull request #117501 from Izorkin/update-mastodon-redis

nixos/mastodon: use unix socket for redis
parents 1fe7393b cf62e325
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ let

    TRUSTED_PROXY_IP = cfg.trustedProxy;
  }
  // 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.smtp.authenticate { SMTP_LOGIN  = cfg.smtp.user; }
  // lib.optionalAttrs (cfg.elasticsearch.host != null) { ES_HOST = cfg.elasticsearch.host; }
@@ -116,9 +117,11 @@ let
      threads = toString (if processCfg.threads == null then cfg.sidekiqThreads else processCfg.threads);
    in {
      after = [ "network.target" "mastodon-init-dirs.service" ]
        ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
        ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
        ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
      requires = [ "mastodon-init-dirs.service" ]
        ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
        ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
        ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
      description = "Mastodon sidekiq${jobClassLabel}";
@@ -146,9 +149,11 @@ let
        name = "mastodon-streaming-${toString i}";
        value = {
          after = [ "network.target" "mastodon-init-dirs.service" ]
            ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
            ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
            ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
          requires = [ "mastodon-init-dirs.service" ]
            ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
            ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
            ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
          wantedBy = [ "mastodon.target" "mastodon-streaming.target" ];
@@ -404,6 +409,12 @@ in {
          type = lib.types.port;
          default = 31637;
        };

        enableUnixSocket = lib.mkOption {
          description = lib.mdDoc "Use Unix socket";
          type = lib.types.bool;
          default = true;
        };
      };

      database = {
@@ -751,9 +762,11 @@ in {

    systemd.services.mastodon-web = {
      after = [ "network.target" "mastodon-init-dirs.service" ]
        ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
        ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
        ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
      requires = [ "mastodon-init-dirs.service" ]
        ++ lib.optional cfg.redis.createLocally "redis-mastodon.service"
        ++ lib.optional databaseActuallyCreateLocally "postgresql.service"
        ++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
      wantedBy = [ "mastodon.target" ];
@@ -834,11 +847,14 @@ in {
      enable = true;
      hostname = lib.mkDefault "${cfg.localDomain}";
    };
    services.redis.servers.mastodon = lib.mkIf (cfg.redis.createLocally && cfg.redis.host == "127.0.0.1") {
    services.redis.servers.mastodon = lib.mkIf cfg.redis.createLocally (lib.mkMerge [
      {
        enable = true;
      }
      (lib.mkIf (!cfg.redis.enableUnixSocket) {
        port = cfg.redis.port;
      bind = "127.0.0.1";
    };
      })
    ]);
    services.postgresql = lib.mkIf databaseActuallyCreateLocally {
      enable = true;
      ensureUsers = [
@@ -859,6 +875,7 @@ in {
        };
      })
      (lib.attrsets.setAttrByPath [ cfg.user "packages" ] [ cfg.package pkgs.imagemagick ])
      (lib.mkIf (cfg.redis.createLocally && cfg.redis.enableUnixSocket) {${config.services.mastodon.user}.extraGroups = [ "redis-mastodon" ];})
    ];

    users.groups.${cfg.group}.members = lib.optional cfg.configureNginx config.services.nginx.user;
+0 −6
Original line number Diff line number Diff line
@@ -34,12 +34,6 @@ in
        pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
      };

      services.redis.servers.mastodon = {
        enable = true;
        bind = "127.0.0.1";
        port = 31637;
      };

      # TODO remove once https://github.com/NixOS/nixpkgs/pull/266270 is resolved.
      services.postgresql.package = pkgs.postgresql_14;