···11+# Pleroma {#module-services-pleroma}
22+33+[Pleroma](https://pleroma.social/) is a lightweight activity pub server.
44+55+## Generating the Pleroma config {#module-services-pleroma-generate-config}
66+77+The `pleroma_ctl` CLI utility will prompt you some questions and it will generate an initial config file. This is an example of usage
88+```ShellSession
99+$ mkdir tmp-pleroma
1010+$ cd tmp-pleroma
1111+$ nix-shell -p pleroma-otp
1212+$ pleroma_ctl instance gen --output config.exs --output-psql setup.psql
1313+```
1414+1515+The `config.exs` file can be further customized following the instructions on the [upstream documentation](https://docs-develop.pleroma.social/backend/configuration/cheatsheet/). Many refinements can be applied also after the service is running.
1616+1717+## Initializing the database {#module-services-pleroma-initialize-db}
1818+1919+First, the Postgresql service must be enabled in the NixOS configuration
2020+```
2121+services.postgresql = {
2222+ enable = true;
2323+ package = pkgs.postgresql_13;
2424+};
2525+```
2626+and activated with the usual
2727+```ShellSession
2828+$ nixos-rebuild switch
2929+```
3030+3131+Then you can create and seed the database, using the `setup.psql` file that you generated in the previous section, by running
3232+```ShellSession
3333+$ sudo -u postgres psql -f setup.psql
3434+```
3535+3636+## Enabling the Pleroma service locally {#module-services-pleroma-enable}
3737+3838+In this section we will enable the Pleroma service only locally, so its configurations can be improved incrementally.
3939+4040+This is an example of configuration, where [](#opt-services.pleroma.configs) option contains the content of the file `config.exs`, generated [in the first section](#module-services-pleroma-generate-config), 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.
4141+```
4242+services.pleroma = {
4343+ enable = true;
4444+ secretConfigFile = "/var/lib/pleroma/secrets.exs";
4545+ configs = [
4646+ ''
4747+ import Config
4848+4949+ config :pleroma, Pleroma.Web.Endpoint,
5050+ url: [host: "pleroma.example.net", scheme: "https", port: 443],
5151+ http: [ip: {127, 0, 0, 1}, port: 4000]
5252+5353+ config :pleroma, :instance,
5454+ name: "Test",
5555+ email: "admin@example.net",
5656+ notify_email: "admin@example.net",
5757+ limit: 5000,
5858+ registrations_open: true
5959+6060+ config :pleroma, :media_proxy,
6161+ enabled: false,
6262+ redirect_on_failure: true
6363+6464+ config :pleroma, Pleroma.Repo,
6565+ adapter: Ecto.Adapters.Postgres,
6666+ username: "pleroma",
6767+ database: "pleroma",
6868+ hostname: "localhost"
6969+7070+ # Configure web push notifications
7171+ config :web_push_encryption, :vapid_details,
7272+ subject: "mailto:admin@example.net"
7373+7474+ # ... TO CONTINUE ...
7575+ ''
7676+ ];
7777+};
7878+```
7979+8080+Secrets must be moved into a file pointed by [](#opt-services.pleroma.secretConfigFile), in our case `/var/lib/pleroma/secrets.exs`. This file can be created copying the previously generated `config.exs` file and then removing all the settings, except the secrets. This is an example
8181+```
8282+# Pleroma instance passwords
8383+8484+import Config
8585+8686+config :pleroma, Pleroma.Web.Endpoint,
8787+ secret_key_base: "<the secret generated by pleroma_ctl>",
8888+ signing_salt: "<the secret generated by pleroma_ctl>"
8989+9090+config :pleroma, Pleroma.Repo,
9191+ password: "<the secret generated by pleroma_ctl>"
9292+9393+# Configure web push notifications
9494+config :web_push_encryption, :vapid_details,
9595+ public_key: "<the secret generated by pleroma_ctl>",
9696+ private_key: "<the secret generated by pleroma_ctl>"
9797+9898+# ... TO CONTINUE ...
9999+```
100100+Note that the lines of the same configuration group are comma separated (i.e. all the lines end with a comma, except the last one), so when the lines with passwords are added or removed, commas must be adjusted accordingly.
101101+102102+The service can be enabled with the usual
103103+```ShellSession
104104+$ nixos-rebuild switch
105105+```
106106+107107+The service is accessible only from the local `127.0.0.1:4000` port. It can be tested using a port forwarding like this
108108+```ShellSession
109109+$ ssh -L 4000:localhost:4000 myuser@example.net
110110+```
111111+and then accessing <http://localhost:4000> from a web browser.
112112+113113+## Creating the admin user {#module-services-pleroma-admin-user}
114114+115115+After Pleroma service is running, all [Pleroma administration utilities](https://docs-develop.pleroma.social/) can be used. In particular an admin user can be created with
116116+```ShellSession
117117+$ pleroma_ctl user new <nickname> <email> --admin --moderator --password <password>
118118+```
119119+120120+## Configuring Nginx {#module-services-pleroma-nginx}
121121+122122+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
123123+[Let's Encrypt](https://letsencrypt.org/) for the TLS certificates
124124+```
125125+security.acme = {
126126+ email = "root@example.net";
127127+ acceptTerms = true;
128128+};
129129+130130+services.nginx = {
131131+ enable = true;
132132+ addSSL = true;
133133+134134+ recommendedTlsSettings = true;
135135+ recommendedOptimisation = true;
136136+ recommendedGzipSettings = true;
137137+138138+ recommendedProxySettings = false;
139139+ # NOTE: if enabled, the NixOS proxy optimizations will override the Pleroma
140140+ # specific settings, and they will enter in conflict.
141141+142142+ virtualHosts = {
143143+ "pleroma.example.net" = {
144144+ http2 = true;
145145+ enableACME = true;
146146+ forceSSL = true;
147147+148148+ locations."/" = {
149149+ proxyPass = "http://127.0.0.1:4000";
150150+151151+ extraConfig = ''
152152+ etag on;
153153+ gzip on;
154154+155155+ add_header 'Access-Control-Allow-Origin' '*' always;
156156+ add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always;
157157+ add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always;
158158+ add_header 'Access-Control-Expose-Headers' 'Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id' always;
159159+ if ($request_method = OPTIONS) {
160160+ return 204;
161161+ }
162162+ add_header X-XSS-Protection "1; mode=block";
163163+ add_header X-Permitted-Cross-Domain-Policies none;
164164+ add_header X-Frame-Options DENY;
165165+ add_header X-Content-Type-Options nosniff;
166166+ add_header Referrer-Policy same-origin;
167167+ add_header X-Download-Options noopen;
168168+ proxy_http_version 1.1;
169169+ proxy_set_header Upgrade $http_upgrade;
170170+ proxy_set_header Connection "upgrade";
171171+ proxy_set_header Host $host;
172172+173173+ client_max_body_size 16m;
174174+ # NOTE: increase if users need to upload very big files
175175+ '';
176176+ };
177177+ };
178178+ };
179179+};
180180+```
+2
nixos/modules/services/networking/pleroma.nix
···147147148148 };
149149 meta.maintainers = with lib.maintainers; [ ninjatrappeur ];
150150+ # Don't edit the docbook xml directly, edit the md and generate it:
151151+ # `pandoc pleroma.md -t docbook --top-level-division=chapter --extract-media=media -f markdown-smart --lua-filter ../../../../doc/build-aux/pandoc-filters/myst-reader/roles.lua --lua-filter ../../../../doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua > pleroma.xml`
150152 meta.doc = ./pleroma.xml;
151153}
+140-85
nixos/modules/services/networking/pleroma.xml
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xmlns:xi="http://www.w3.org/2001/XInclude"
44- version="5.0"
55- xml:id="module-services-pleroma">
66- <title>Pleroma</title>
77- <para>
88- <link xlink:href="https://pleroma.social/">Pleroma</link> is a lightweight activity pub server.</para>
99- <section xml:id="module-services-pleroma-generate-config">
1010- <title>Generating the Pleroma config</title>
1111- <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
1212-<programlisting>
1313-<prompt>$ </prompt>mkdir tmp-pleroma
1414-<prompt>$ </prompt>cd tmp-pleroma
1515-<prompt>$ </prompt>nix-shell -p pleroma-otp
1616-<prompt>$ </prompt>pleroma_ctl instance gen --output config.exs --output-psql setup.psql
11+<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="module-services-pleroma">
22+ <title>Pleroma</title>
33+ <para>
44+ <link xlink:href="https://pleroma.social/">Pleroma</link> is a
55+ lightweight activity pub server.
66+ </para>
77+ <section xml:id="module-services-pleroma-generate-config">
88+ <title>Generating the Pleroma config</title>
99+ <para>
1010+ The <literal>pleroma_ctl</literal> CLI utility will prompt you
1111+ some questions and it will generate an initial config file. This
1212+ is an example of usage
1313+ </para>
1414+ <programlisting>
1515+$ mkdir tmp-pleroma
1616+$ cd tmp-pleroma
1717+$ nix-shell -p pleroma-otp
1818+$ pleroma_ctl instance gen --output config.exs --output-psql setup.psql
1719</programlisting>
1818- </para>
1919- <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>
2020- </section>
2121- <section xml:id="module-services-pleroma-initialize-db">
2222- <title>Initializing the database</title>
2323- <para>First, the Postgresql service must be enabled in the NixOS configuration
2424-<programlisting>
2020+ <para>
2121+ The <literal>config.exs</literal> file can be further customized
2222+ following the instructions on the
2323+ <link xlink:href="https://docs-develop.pleroma.social/backend/configuration/cheatsheet/">upstream
2424+ documentation</link>. Many refinements can be applied also after
2525+ the service is running.
2626+ </para>
2727+ </section>
2828+ <section xml:id="module-services-pleroma-initialize-db">
2929+ <title>Initializing the database</title>
3030+ <para>
3131+ First, the Postgresql service must be enabled in the NixOS
3232+ configuration
3333+ </para>
3434+ <programlisting>
2535services.postgresql = {
2636 enable = true;
2737 package = pkgs.postgresql_13;
2838};
2939</programlisting>
3030-and activated with the usual
3131-<programlisting>
3232-<prompt>$ </prompt>nixos-rebuild switch
4040+ <para>
4141+ and activated with the usual
4242+ </para>
4343+ <programlisting>
4444+$ nixos-rebuild switch
3345</programlisting>
3434- </para>
3535- <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
3636-<programlisting>
3737-<prompt>$ </prompt>sudo -u postgres psql -f setup.psql
4646+ <para>
4747+ Then you can create and seed the database, using the
4848+ <literal>setup.psql</literal> file that you generated in the
4949+ previous section, by running
5050+ </para>
5151+ <programlisting>
5252+$ sudo -u postgres psql -f setup.psql
3853</programlisting>
3939- </para>
4040- </section>
4141- <section xml:id="module-services-pleroma-enable">
4242- <title>Enabling the Pleroma service locally</title>
4343- <para>In this section we will enable the Pleroma service only locally, so its configurations can be improved incrementally.</para>
4444- <para>This is an example of configuration, where <link linkend="opt-services.pleroma.configs">services.pleroma.configs</link> option contains the content of the file <literal>config.exs</literal>, generated <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.
4545-<programlisting>
5454+ </section>
5555+ <section xml:id="module-services-pleroma-enable">
5656+ <title>Enabling the Pleroma service locally</title>
5757+ <para>
5858+ In this section we will enable the Pleroma service only locally,
5959+ so its configurations can be improved incrementally.
6060+ </para>
6161+ <para>
6262+ This is an example of configuration, where
6363+ <xref linkend="opt-services.pleroma.configs"></xref> option
6464+ contains the content of the file <literal>config.exs</literal>,
6565+ generated
6666+ <link linkend="module-services-pleroma-generate-config">in the
6767+ first section</link>, but with the secrets (database password,
6868+ endpoint secret key, salts, etc.) removed. Removing secrets is
6969+ important, because otherwise they will be stored publicly in the
7070+ Nix store.
7171+ </para>
7272+ <programlisting>
4673services.pleroma = {
4774 enable = true;
4848- secretConfigFile = "/var/lib/pleroma/secrets.exs";
7575+ secretConfigFile = "/var/lib/pleroma/secrets.exs";
4976 configs = [
5077 ''
5178 import Config
52795380 config :pleroma, Pleroma.Web.Endpoint,
5454- url: [host: "pleroma.example.net", scheme: "https", port: 443],
8181+ url: [host: "pleroma.example.net", scheme: "https", port: 443],
5582 http: [ip: {127, 0, 0, 1}, port: 4000]
56835784 config :pleroma, :instance,
5858- name: "Test",
5959- email: "admin@example.net",
6060- notify_email: "admin@example.net",
8585+ name: "Test",
8686+ email: "admin@example.net",
8787+ notify_email: "admin@example.net",
6188 limit: 5000,
6289 registrations_open: true
6390···67946895 config :pleroma, Pleroma.Repo,
6996 adapter: Ecto.Adapters.Postgres,
7070- username: "pleroma",
7171- database: "pleroma",
7272- hostname: "localhost"
9797+ username: "pleroma",
9898+ database: "pleroma",
9999+ hostname: "localhost"
7310074101 # Configure web push notifications
75102 config :web_push_encryption, :vapid_details,
7676- subject: "mailto:admin@example.net"
103103+ subject: "mailto:admin@example.net"
7710478105 # ... TO CONTINUE ...
79106 ''
80107 ];
81108};
82109</programlisting>
8383- </para>
8484- <para>Secrets must be moved into a file pointed by <link linkend="opt-services.pleroma.secretConfigFile">services.pleroma.secretConfigFile</link>, in our case <literal>/var/lib/pleroma/secrets.exs</literal>. This file can be created copying the previously generated <literal>config.exs</literal> file and then removing all the settings, except the secrets. This is an example
8585-<programlisting>
110110+ <para>
111111+ Secrets must be moved into a file pointed by
112112+ <xref linkend="opt-services.pleroma.secretConfigFile"></xref>, in
113113+ our case <literal>/var/lib/pleroma/secrets.exs</literal>. This
114114+ file can be created copying the previously generated
115115+ <literal>config.exs</literal> file and then removing all the
116116+ settings, except the secrets. This is an example
117117+ </para>
118118+ <programlisting>
86119# Pleroma instance passwords
8712088121import Config
8912290123config :pleroma, Pleroma.Web.Endpoint,
9191- secret_key_base: "<the secret generated by pleroma_ctl>",
9292- signing_salt: "<the secret generated by pleroma_ctl>"
124124+ secret_key_base: "<the secret generated by pleroma_ctl>",
125125+ signing_salt: "<the secret generated by pleroma_ctl>"
9312694127config :pleroma, Pleroma.Repo,
9595- password: "<the secret generated by pleroma_ctl>"
128128+ password: "<the secret generated by pleroma_ctl>"
9612997130# Configure web push notifications
98131config :web_push_encryption, :vapid_details,
9999- public_key: "<the secret generated by pleroma_ctl>",
100100- private_key: "<the secret generated by pleroma_ctl>"
132132+ public_key: "<the secret generated by pleroma_ctl>",
133133+ private_key: "<the secret generated by pleroma_ctl>"
101134102135# ... TO CONTINUE ...
103136</programlisting>
104104- Note that the lines of the same configuration group are comma separated (i.e. all the lines end with a comma, except the last one), so when the lines with passwords are added or removed, commas must be adjusted accordingly.</para>
105105-106106- <para>The service can be enabled with the usual
107107-<programlisting>
108108-<prompt>$ </prompt>nixos-rebuild switch
137137+ <para>
138138+ Note that the lines of the same configuration group are comma
139139+ separated (i.e. all the lines end with a comma, except the last
140140+ one), so when the lines with passwords are added or removed,
141141+ commas must be adjusted accordingly.
142142+ </para>
143143+ <para>
144144+ The service can be enabled with the usual
145145+ </para>
146146+ <programlisting>
147147+$ nixos-rebuild switch
109148</programlisting>
110110- </para>
111111- <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
112112-<programlisting>
113113-<prompt>$ </prompt>ssh -L 4000:localhost:4000 myuser@example.net
149149+ <para>
150150+ The service is accessible only from the local
151151+ <literal>127.0.0.1:4000</literal> port. It can be tested using a
152152+ port forwarding like this
153153+ </para>
154154+ <programlisting>
155155+$ ssh -L 4000:localhost:4000 myuser@example.net
114156</programlisting>
115115-and then accessing <link xlink:href="http://localhost:4000">http://localhost:4000</link> from a web browser.</para>
116116- </section>
117117- <section xml:id="module-services-pleroma-admin-user">
118118- <title>Creating the admin user</title>
119119- <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
120120-<programlisting>
121121-<prompt>$ </prompt>pleroma_ctl user new <nickname> <email> --admin --moderator --password <password>
157157+ <para>
158158+ and then accessing
159159+ <link xlink:href="http://localhost:4000" role="uri">http://localhost:4000</link>
160160+ from a web browser.
161161+ </para>
162162+ </section>
163163+ <section xml:id="module-services-pleroma-admin-user">
164164+ <title>Creating the admin user</title>
165165+ <para>
166166+ After Pleroma service is running, all
167167+ <link xlink:href="https://docs-develop.pleroma.social/">Pleroma
168168+ administration utilities</link> can be used. In particular an
169169+ admin user can be created with
170170+ </para>
171171+ <programlisting>
172172+$ pleroma_ctl user new <nickname> <email> --admin --moderator --password <password>
122173</programlisting>
123123- </para>
124124- </section>
125125- <section xml:id="module-services-pleroma-nginx">
126126- <title>Configuring Nginx</title>
127127- <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
128128-<link xlink:href="https://letsencrypt.org/">Let's Encrypt</link> for the TLS certificates
129129-<programlisting>
174174+ </section>
175175+ <section xml:id="module-services-pleroma-nginx">
176176+ <title>Configuring Nginx</title>
177177+ <para>
178178+ In this configuration, Pleroma is listening only on the local port
179179+ 4000. Nginx can be configured as a Reverse Proxy, for forwarding
180180+ requests from public ports to the Pleroma service. This is an
181181+ example of configuration, using
182182+ <link xlink:href="https://letsencrypt.org/">Let's Encrypt</link>
183183+ for the TLS certificates
184184+ </para>
185185+ <programlisting>
130186security.acme = {
131131- email = "root@example.net";
187187+ email = "root@example.net";
132188 acceptTerms = true;
133189};
134190···145201 # specific settings, and they will enter in conflict.
146202147203 virtualHosts = {
148148- "pleroma.example.net" = {
204204+ "pleroma.example.net" = {
149205 http2 = true;
150206 enableACME = true;
151207 forceSSL = true;
152208153153- locations."/" = {
154154- proxyPass = "http://127.0.0.1:4000";
209209+ locations."/" = {
210210+ proxyPass = "http://127.0.0.1:4000";
155211156212 extraConfig = ''
157213 etag on;
···164220 if ($request_method = OPTIONS) {
165221 return 204;
166222 }
167167- add_header X-XSS-Protection "1; mode=block";
223223+ add_header X-XSS-Protection "1; mode=block";
168224 add_header X-Permitted-Cross-Domain-Policies none;
169225 add_header X-Frame-Options DENY;
170226 add_header X-Content-Type-Options nosniff;
···172228 add_header X-Download-Options noopen;
173229 proxy_http_version 1.1;
174230 proxy_set_header Upgrade $http_upgrade;
175175- proxy_set_header Connection "upgrade";
231231+ proxy_set_header Connection "upgrade";
176232 proxy_set_header Host $host;
177233178234 client_max_body_size 16m;
···183239 };
184240};
185241</programlisting>
186186- </para>
187187- </section>
242242+ </section>
188243</chapter>