2023-01-10 11:34:37 +00:00
|
|
|
|
<!-- Do not edit this file directly, edit its companion .md instead
|
|
|
|
|
and regenerate this file using nixos/doc/manual/md-to-db.sh -->
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="module-services-pleroma">
|
|
|
|
|
<title>Pleroma</title>
|
|
|
|
|
<para>
|
|
|
|
|
<link xlink:href="https://pleroma.social/">Pleroma</link> is a
|
|
|
|
|
lightweight activity pub server.
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</para>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<section xml:id="module-services-pleroma-generate-config">
|
|
|
|
|
<title>Generating the Pleroma config</title>
|
|
|
|
|
<para>
|
|
|
|
|
The <literal>pleroma_ctl</literal> CLI utility will prompt you
|
|
|
|
|
some questions and it will generate an initial config file. This
|
|
|
|
|
is an example of usage
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ mkdir tmp-pleroma
|
|
|
|
|
$ cd tmp-pleroma
|
|
|
|
|
$ nix-shell -p pleroma-otp
|
|
|
|
|
$ pleroma_ctl instance gen --output config.exs --output-psql setup.psql
|
|
|
|
|
</programlisting>
|
|
|
|
|
<para>
|
|
|
|
|
The <literal>config.exs</literal> file can be further customized
|
|
|
|
|
following the instructions on the
|
|
|
|
|
<link xlink:href="https://docs-develop.pleroma.social/backend/configuration/cheatsheet/">upstream
|
|
|
|
|
documentation</link>. Many refinements can be applied also after
|
|
|
|
|
the service is running.
|
|
|
|
|
</para>
|
|
|
|
|
</section>
|
|
|
|
|
<section xml:id="module-services-pleroma-initialize-db">
|
|
|
|
|
<title>Initializing the database</title>
|
|
|
|
|
<para>
|
|
|
|
|
First, the Postgresql service must be enabled in the NixOS
|
|
|
|
|
configuration
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2021-08-15 17:28:21 +00:00
|
|
|
|
services.postgresql = {
|
|
|
|
|
enable = true;
|
|
|
|
|
package = pkgs.postgresql_13;
|
|
|
|
|
};
|
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
and activated with the usual
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ nixos-rebuild switch
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
Then you can create and seed the database, using the
|
|
|
|
|
<literal>setup.psql</literal> file that you generated in the
|
|
|
|
|
previous section, by running
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ sudo -u postgres psql -f setup.psql
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
</section>
|
|
|
|
|
<section xml:id="module-services-pleroma-enable">
|
|
|
|
|
<title>Enabling the Pleroma service locally</title>
|
|
|
|
|
<para>
|
|
|
|
|
In this section we will enable the Pleroma service only locally,
|
|
|
|
|
so its configurations can be improved incrementally.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
This is an example of configuration, where
|
2023-01-05 05:16:46 +00:00
|
|
|
|
<xref linkend="opt-services.pleroma.configs" /> option contains
|
|
|
|
|
the content of the file <literal>config.exs</literal>, generated
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<link linkend="module-services-pleroma-generate-config">in the
|
|
|
|
|
first section</link>, but with the secrets (database password,
|
|
|
|
|
endpoint secret key, salts, etc.) removed. Removing secrets is
|
|
|
|
|
important, because otherwise they will be stored publicly in the
|
|
|
|
|
Nix store.
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2021-08-15 17:28:21 +00:00
|
|
|
|
services.pleroma = {
|
|
|
|
|
enable = true;
|
2023-01-03 05:13:51 +00:00
|
|
|
|
secretConfigFile = "/var/lib/pleroma/secrets.exs";
|
2021-08-15 17:28:21 +00:00
|
|
|
|
configs = [
|
|
|
|
|
''
|
|
|
|
|
import Config
|
|
|
|
|
|
|
|
|
|
config :pleroma, Pleroma.Web.Endpoint,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
url: [host: "pleroma.example.net", scheme: "https", port: 443],
|
2021-08-15 17:28:21 +00:00
|
|
|
|
http: [ip: {127, 0, 0, 1}, port: 4000]
|
|
|
|
|
|
|
|
|
|
config :pleroma, :instance,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
name: "Test",
|
|
|
|
|
email: "admin@example.net",
|
|
|
|
|
notify_email: "admin@example.net",
|
2021-08-15 17:28:21 +00:00
|
|
|
|
limit: 5000,
|
|
|
|
|
registrations_open: true
|
|
|
|
|
|
|
|
|
|
config :pleroma, :media_proxy,
|
|
|
|
|
enabled: false,
|
|
|
|
|
redirect_on_failure: true
|
|
|
|
|
|
|
|
|
|
config :pleroma, Pleroma.Repo,
|
|
|
|
|
adapter: Ecto.Adapters.Postgres,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
username: "pleroma",
|
|
|
|
|
database: "pleroma",
|
|
|
|
|
hostname: "localhost"
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
# Configure web push notifications
|
|
|
|
|
config :web_push_encryption, :vapid_details,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
subject: "mailto:admin@example.net"
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
# ... TO CONTINUE ...
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
Secrets must be moved into a file pointed by
|
2023-01-05 05:16:46 +00:00
|
|
|
|
<xref linkend="opt-services.pleroma.secretConfigFile" />, in our
|
|
|
|
|
case <literal>/var/lib/pleroma/secrets.exs</literal>. This file
|
|
|
|
|
can be created copying the previously generated
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<literal>config.exs</literal> file and then removing all the
|
|
|
|
|
settings, except the secrets. This is an example
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2021-08-15 17:28:21 +00:00
|
|
|
|
# Pleroma instance passwords
|
|
|
|
|
|
|
|
|
|
import Config
|
|
|
|
|
|
|
|
|
|
config :pleroma, Pleroma.Web.Endpoint,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
secret_key_base: "<the secret generated by pleroma_ctl>",
|
|
|
|
|
signing_salt: "<the secret generated by pleroma_ctl>"
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
config :pleroma, Pleroma.Repo,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
password: "<the secret generated by pleroma_ctl>"
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
# Configure web push notifications
|
|
|
|
|
config :web_push_encryption, :vapid_details,
|
2023-01-03 05:13:51 +00:00
|
|
|
|
public_key: "<the secret generated by pleroma_ctl>",
|
|
|
|
|
private_key: "<the secret generated by pleroma_ctl>"
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
# ... TO CONTINUE ...
|
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
Note that the lines of the same configuration group are comma
|
2023-01-05 05:16:46 +00:00
|
|
|
|
separated (i.e. all the lines end with a comma, except the last
|
2023-01-03 05:13:51 +00:00
|
|
|
|
one), so when the lines with passwords are added or removed,
|
|
|
|
|
commas must be adjusted accordingly.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
The service can be enabled with the usual
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ nixos-rebuild switch
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
The service is accessible only from the local
|
|
|
|
|
<literal>127.0.0.1:4000</literal> port. It can be tested using a
|
|
|
|
|
port forwarding like this
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ ssh -L 4000:localhost:4000 myuser@example.net
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
<para>
|
|
|
|
|
and then accessing
|
2023-01-05 05:16:46 +00:00
|
|
|
|
<link xlink:href="http://localhost:4000">http://localhost:4000</link>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
from a web browser.
|
|
|
|
|
</para>
|
|
|
|
|
</section>
|
|
|
|
|
<section xml:id="module-services-pleroma-admin-user">
|
|
|
|
|
<title>Creating the admin user</title>
|
|
|
|
|
<para>
|
|
|
|
|
After Pleroma service is running, all
|
|
|
|
|
<link xlink:href="https://docs-develop.pleroma.social/">Pleroma
|
|
|
|
|
administration utilities</link> can be used. In particular an
|
|
|
|
|
admin user can be created with
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
|
|
|
|
$ pleroma_ctl user new <nickname> <email> --admin --moderator --password <password>
|
2021-08-15 17:28:21 +00:00
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
</section>
|
|
|
|
|
<section xml:id="module-services-pleroma-nginx">
|
|
|
|
|
<title>Configuring Nginx</title>
|
|
|
|
|
<para>
|
|
|
|
|
In this configuration, Pleroma is listening only on the local port
|
|
|
|
|
4000. Nginx can be configured as a Reverse Proxy, for forwarding
|
|
|
|
|
requests from public ports to the Pleroma service. This is an
|
|
|
|
|
example of configuration, using
|
2023-01-04 05:56:24 +00:00
|
|
|
|
<link xlink:href="https://letsencrypt.org/">Let’s Encrypt</link>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
for the TLS certificates
|
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2021-08-15 17:28:21 +00:00
|
|
|
|
security.acme = {
|
2023-01-03 05:13:51 +00:00
|
|
|
|
email = "root@example.net";
|
2021-08-15 17:28:21 +00:00
|
|
|
|
acceptTerms = true;
|
|
|
|
|
};
|
2020-11-08 14:05:37 +00:00
|
|
|
|
|
2021-08-15 17:28:21 +00:00
|
|
|
|
services.nginx = {
|
|
|
|
|
enable = true;
|
|
|
|
|
addSSL = true;
|
|
|
|
|
|
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
|
|
|
|
|
|
recommendedProxySettings = false;
|
|
|
|
|
# NOTE: if enabled, the NixOS proxy optimizations will override the Pleroma
|
|
|
|
|
# specific settings, and they will enter in conflict.
|
|
|
|
|
|
|
|
|
|
virtualHosts = {
|
2023-01-03 05:13:51 +00:00
|
|
|
|
"pleroma.example.net" = {
|
2021-08-15 17:28:21 +00:00
|
|
|
|
http2 = true;
|
|
|
|
|
enableACME = true;
|
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
2023-01-03 05:13:51 +00:00
|
|
|
|
locations."/" = {
|
|
|
|
|
proxyPass = "http://127.0.0.1:4000";
|
2021-08-15 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
|
etag on;
|
|
|
|
|
gzip on;
|
|
|
|
|
|
|
|
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
|
|
|
add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always;
|
|
|
|
|
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always;
|
|
|
|
|
add_header 'Access-Control-Expose-Headers' 'Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id' always;
|
|
|
|
|
if ($request_method = OPTIONS) {
|
|
|
|
|
return 204;
|
|
|
|
|
}
|
2023-01-03 05:13:51 +00:00
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
2021-08-15 17:28:21 +00:00
|
|
|
|
add_header X-Permitted-Cross-Domain-Policies none;
|
|
|
|
|
add_header X-Frame-Options DENY;
|
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
|
add_header Referrer-Policy same-origin;
|
|
|
|
|
add_header X-Download-Options noopen;
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
2023-01-03 05:13:51 +00:00
|
|
|
|
proxy_set_header Connection "upgrade";
|
2021-08-15 17:28:21 +00:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
|
|
|
|
client_max_body_size 16m;
|
|
|
|
|
# NOTE: increase if users need to upload very big files
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
</programlisting>
|
2023-01-03 05:13:51 +00:00
|
|
|
|
</section>
|
2020-11-08 14:05:37 +00:00
|
|
|
|
</chapter>
|