Mastodon

Free and open-source software platform for decentralized social networking.

Declared in: projects/Mastodon/default.nix

Demo

Implement missing demo

Options

services.mastodon
services.mastodon.activeRecordEncryptionDeterministicKeyFile

This key must be set to enable the Active Record Encryption feature within Rails that Mastodon uses to encrypt and decrypt some database attributes. A new Active Record keys can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; RAILS_ENV=production ./bin/rails db:encryption:init

If this file does not exist, it will be created with a new Active Record keys.

Type:
string
Default:
"/var/lib/mastodon/secrets/active-record-encryption-deterministic-key"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.activeRecordEncryptionKeyDerivationSaltFile

This key must be set to enable the Active Record Encryption feature within Rails that Mastodon uses to encrypt and decrypt some database attributes. A new Active Record keys can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; RAILS_ENV=production ./bin/rails db:encryption:init

If this file does not exist, it will be created with a new Active Record keys.

Type:
string
Default:
"/var/lib/mastodon/secrets/active-record-encryption-key-derivation-salt"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.activeRecordEncryptionPrimaryKeyFile

This key must be set to enable the Active Record Encryption feature within Rails that Mastodon uses to encrypt and decrypt some database attributes. A new Active Record keys can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; RAILS_ENV=production ./bin/rails db:encryption:init

If this file does not exist, it will be created with a new Active Record keys.

Type:
string
Default:
"/var/lib/mastodon/secrets/active-record-encryption-primary-key"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.automaticMigrations

Do automatic database migrations.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.configureNginx

Configure nginx as a reverse proxy for mastodon. Note that this makes some assumptions on your setup, and sets settings that will affect other virtualHosts running on your nginx instance, if any. Alternatively you can configure a reverse-proxy of your choice to serve these paths:

/ -> ${pkgs.mastodon}/public

/ -> 127.0.0.1:{{ webPort }} (If there was no file in the directory above.)

/system/ -> /var/lib/mastodon/public-system/

/api/v1/streaming/ -> 127.0.0.1:{{ streamingPort }}

Make sure that websockets are forwarded properly. You might want to set up caching of some requests. Take a look at mastodon's provided nginx configuration at https://github.com/mastodon/mastodon/blob/master/dist/nginx.conf.

Type:
boolean
Default:
false
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.createLocally

Configure local PostgreSQL database server for Mastodon.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.host

Database host address or unix socket.

Type:
string
Default:
"/run/postgresql"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.name

Database name.

Type:
string
Default:
"mastodon"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.passwordFile

A file containing the password corresponding to {option}database.user.

Type:
null or absolute path
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.port

Database host port.

Type:
null or 16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
if config.services.mastodon.database.createLocally then null else 5432
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.database.user

Database user.

Type:
string
Default:
"mastodon"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.host

Elasticsearch host. If it is not null, Elasticsearch full text search will be enabled.

Type:
null or string
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.passwordFile

Path to file containing password for optionally authenticating with Elasticsearch.

Type:
null or absolute path
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.port

Elasticsearch port.

Type:
16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
9200
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.prefix

If provided, adds a prefix to indexes in Elasticsearch. This allows to use the same Elasticsearch cluster between different projects or Mastodon servers.

Type:
null or string
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.preset

It controls the ElasticSearch indices configuration (number of shards and replica).

Type:
one of "single_node_cluster", "small_cluster", "large_cluster"
Default:
"single_node_cluster"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.elasticsearch.user

Used for optionally authenticating with Elasticsearch.

Type:
null or string
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.enable

Whether to enable Mastodon, a federated social network server.

Type:
boolean
Default:
false
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.enableUnixSocket

Instead of binding to an IP address like 127.0.0.1, you may bind to a Unix socket. This variable is process-specific, e.g. you need different values for every process, and it works for both web (Puma) processes and streaming API (Node.js) processes.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.extraConfig

Extra environment variables to pass to all mastodon services.

Type:
attribute set
Default:
{ }
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.extraEnvFiles

Extra environment files to pass to all mastodon services. Useful for passing down environmental secrets.

Type:
list of absolute path
Default:
[ ]
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.group

Group under which mastodon runs.

Type:
string
Default:
"mastodon"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.localDomain

The domain serving your Mastodon instance.

Type:
string
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.mediaAutoRemove.enable

Automatically remove remote media attachments and preview cards older than the configured amount of days.

Recommended in https://docs.joinmastodon.org/admin/setup/.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.mediaAutoRemove.olderThanDays

How old remote media needs to be in order to be removed.

Type:
signed integer
Default:
30
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.mediaAutoRemove.startAt

How often to remove remote media.

The format is described in {manpage}systemd.time(7).

Type:
string
Default:
"daily"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.package

The mastodon package to use.

Type:
package
Default:
pkgs.mastodon
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.redis.createLocally

Configure local Redis server for Mastodon.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.redis.enableUnixSocket

Use Unix socket

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.redis.host

Redis host.

Type:
null or string
Default:
if config.services.mastodon.redis.createLocally && !config.services.mastodon.redis.enableUnixSocket then "127.0.0.1" else null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.redis.passwordFile

A file containing the password for Redis database.

Type:
null or absolute path
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.redis.port

Redis port.

Type:
null or 16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
if config.services.mastodon.redis.createLocally && !config.services.mastodon.redis.enableUnixSocket then 31637 else null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.secretKeyBaseFile

Path to file containing the secret key base. A new secret key base can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; bin/bundle exec rails secret

If this file does not exist, it will be created with a new secret key base.

Type:
string
Default:
"/var/lib/mastodon/secrets/secret-key-base"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.sidekiqPort

TCP port used by the mastodon-sidekiq service.

Type:
16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
55002
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.sidekiqProcesses

How many Sidekiq processes should be used to handle background jobs, and which job classes they handle. Read the upstream documentation before configuring this!

Type:
attribute set of (submodule)
Default:
{ all = { jobClasses = [ ]; threads = null; }; }
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.sidekiqProcesses..jobClasses

If not empty, which job classes should be executed by this process. Only one process should handle the 'scheduler' class. If left empty, this process will handle the 'scheduler' class.

Type:
list of (one of "default", "fasp", "push", "pull", "mailers", "scheduler", "ingress")
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.sidekiqProcesses..threads

Number of threads this process should use for executing jobs. If null, the configured sidekiqThreads are used.

Type:
null or signed integer
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.sidekiqThreads

Worker threads used by the mastodon-sidekiq-all service. If sidekiqProcesses is configured and any processes specify null threads, this value is used.

Type:
signed integer
Default:
25
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.authenticate

Authenticate with the SMTP server using username and password.

Type:
boolean
Default:
false
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.createLocally

Configure local Postfix SMTP server for Mastodon.

Type:
boolean
Default:
true
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.fromAddress

"From" address used when sending Emails to users.

Type:
string
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.host

SMTP host used when sending emails to users.

Type:
string
Default:
"127.0.0.1"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.passwordFile

Path to file containing the SMTP password.

Type:
null or absolute path
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.port

SMTP port used when sending emails to users.

Type:
16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
25
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.smtp.user

SMTP login name.

Type:
null or string
Default:
null
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.streamingProcesses

Number of processes used by the mastodon-streaming service. Please define this explicitly, recommended is the amount of your CPU cores minus one.

Type:
positive integer, meaning >0
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.trustedProxy

You need to set it to the IP from which your reverse proxy sends requests to Mastodon's web process, otherwise Mastodon will record the reverse proxy's own IP as the IP of all requests, which would be bad because IP addresses are used for important rate limits and security functions.

Type:
string
Default:
"127.0.0.1"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.user

User under which mastodon runs. If it is set to "mastodon", that user will be created, otherwise it should be set to the name of a user created elsewhere. In both cases, the mastodon package will be added to the user's package set and a tootctl wrapper to system packages that switches to the configured account and load the right environment.

Type:
string
Default:
"mastodon"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.vapidPrivateKeyFile

Path to file containing the private key used for Web Push Voluntary Application Server Identification. A new keypair can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; bin/rake webpush:generate_keys

If this file does not exist, it will be created with a new private key.

Type:
string
Default:
"/var/lib/mastodon/secrets/vapid-private-key"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.vapidPublicKeyFile

Path to file containing the public key used for Web Push Voluntary Application Server Identification. A new keypair can be generated by running:

nix build -f '<nixpkgs>' mastodon; cd result; RAILS_ENV=production bin/rake webpush:generate_keys

If {option}mastodon.vapidPrivateKeyFiledoes not exist, it and this file will be created with a new keypair.

Type:
string
Default:
"/var/lib/mastodon/secrets/vapid-public-key"
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.webPort

TCP port used by the mastodon-web service.

Type:
16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default:
55001
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.webProcesses

Processes used by the mastodon-web service.

Type:
signed integer
Default:
2
Declared in:
nixos/modules/services/web-apps/mastodon.nix
services.mastodon.webThreads

Threads per process used by the mastodon-web service.

Type:
signed integer
Default:
5
Declared in:
nixos/modules/services/web-apps/mastodon.nix

Examples

This project is funded by NLnet through these subgrants:

Commons
Mastodon-for-institutions
Entrust
Mastodon-Quoting
Review
Mastodon