1 { lib, pkgs, config, ... }:
3 env = config.myEnv.tools.mastodon;
4 root = "${mcfg.workdir}/public/";
5 cfg = config.myServices.websites.tools.mastodon;
6 mcfg = config.immaeServices.mastodon;
8 options.myServices.websites.tools.mastodon = {
9 enable = lib.mkEnableOption "enable mastodon's website";
12 config = lib.mkIf cfg.enable {
13 myServices.chatonsProperties.services.mastodon = {
14 file.datetime = "2022-08-21T19:50:00";
17 description = "Your self-hosted, globally interconnected microblogging community";
18 website = "https://mastodon.immae.eu/";
19 logo = "https://mastodon.immae.eu/apple-touch-icon.png";
21 status.description = "OK";
22 registration."" = ["MEMBER" "CLIENT"];
23 registration.load = "OPEN";
24 install.type = "PACKAGE";
28 website = "https://joinmastodon.org/";
29 license.url = "https://github.com/tootsuite/mastodon/blob/master/LICENSE";
30 license.name = "GNU General Public License v3.0";
31 version = mcfg.package.version;
32 source.url = "https://github.com/tootsuite/mastodon";
35 secrets.keys."webapps/tools-mastodon" = {
40 REDIS_HOST=${env.redis.host}
41 REDIS_PORT=${env.redis.port}
42 REDIS_DB=${env.redis.db}
43 DB_HOST=${env.postgresql.socket}
44 DB_USER=${env.postgresql.user}
45 DB_NAME=${env.postgresql.database}
46 DB_PASS=${env.postgresql.password}
47 DB_PORT=${env.postgresql.port}
49 LOCAL_DOMAIN=mastodon.immae.eu
51 ALTERNATE_DOMAINS=immae.eu
53 PAPERCLIP_SECRET=${env.paperclip_secret}
54 SECRET_KEY_BASE=${env.secret_key_base}
55 OTP_SECRET=${env.otp_secret}
57 VAPID_PRIVATE_KEY=${env.vapid.private}
58 VAPID_PUBLIC_KEY=${env.vapid.public}
60 SMTP_DELIVERY_METHOD=sendmail
61 SMTP_FROM_ADDRESS=mastodon@tools.immae.eu
62 SENDMAIL_LOCATION="/run/wrappers/bin/sendmail"
63 PAPERCLIP_ROOT_PATH=${mcfg.dataDir}
65 STREAMING_CLUSTER_NUM=1
69 # LDAP authentication (optional)
71 LDAP_HOST=${env.ldap.host}
73 LDAP_METHOD=simple_tls
74 LDAP_BASE="${env.ldap.base}"
75 LDAP_BIND_DN="${env.ldap.dn}"
76 LDAP_PASSWORD="${env.ldap.password}"
78 LDAP_SEARCH_FILTER="${env.ldap.filter}"
81 immaeServices.mastodon = {
83 configFile = config.secrets.fullPaths."webapps/tools-mastodon";
84 socketsPrefix = "live_immae";
85 dataDir = "/var/lib/mastodon_immae";
87 services.filesWatcher.mastodon-streaming = {
89 paths = [ mcfg.configFile ];
91 services.filesWatcher.mastodon-web = {
93 paths = [ mcfg.configFile ];
95 services.filesWatcher.mastodon-sidekiq = {
97 paths = [ mcfg.configFile ];
101 services.websites.env.tools.modules = [
102 "headers" "proxy" "proxy_wstunnel" "proxy_http"
104 services.websites.env.tools.vhostConfs.mastodon = {
105 certName = "eldiron";
107 hosts = ["mastodon.immae.eu" ];
110 Header always set Referrer-Policy "strict-origin-when-cross-origin"
111 Header always set Strict-Transport-Security "max-age=31536000"
113 <LocationMatch "^/(assets|avatars|emoji|headers|packs|sounds|system)>
114 Header always set Cache-Control "public, max-age=31536000, immutable"
119 RequestHeader set X-Forwarded-Proto "https"
123 RewriteRule ^/api/v1/streaming/(.+)$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/$1 [P,NE,QSA,L]
124 RewriteRule ^/api/v1/streaming/public$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/public [P,NE,QSA,L]
125 RewriteRule ^/api/v1/streaming/$ unix://${mcfg.sockets.node}|ws://mastodon.immae.eu/ [P,NE,QSA,L]
126 RewriteCond %{REQUEST_URI} !/500.html
127 RewriteCond %{REQUEST_URI} !/sw.js
128 RewriteCond %{REQUEST_URI} !/embed.js
129 RewriteCond %{REQUEST_URI} !/robots.txt
130 RewriteCond %{REQUEST_URI} !/manifest.json
131 RewriteCond %{REQUEST_URI} !/browserconfig.xml
132 RewriteCond %{REQUEST_URI} !/mask-icon.svg
133 RewriteCond %{REQUEST_URI} !^(/.*\.(png|ico|gif)$)
134 RewriteCond %{REQUEST_URI} !^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge)
135 RewriteRule ^/(.*)$ unix:///run/mastodon/live_immae_puma.sock|http://mastodon.immae.eu/$1 [P,NE,QSA,L]
136 ProxyPassReverse / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/
138 Alias /system ${mcfg.dataDir}
140 <Directory ${mcfg.dataDir}>
147 Options -MultiViews +FollowSymlinks
150 ErrorDocument 500 /500.html
151 ErrorDocument 501 /500.html
152 ErrorDocument 502 /500.html
153 ErrorDocument 503 /500.html
154 ErrorDocument 504 /500.html