]>
Commit | Line | Data |
---|---|---|
ab8f306d | 1 | { lib, pkgs, config, ... }: |
35a397cd | 2 | let |
ab8f306d | 3 | env = config.myEnv.tools.mastodon; |
750fe5a4 | 4 | root = "${mcfg.workdir}/public/"; |
4288c2f2 | 5 | cfg = config.myServices.websites.tools.mastodon; |
1a64deeb | 6 | mcfg = config.immaeServices.mastodon; |
35a397cd | 7 | in { |
4288c2f2 | 8 | options.myServices.websites.tools.mastodon = { |
35a397cd IB |
9 | enable = lib.mkEnableOption "enable mastodon's website"; |
10 | }; | |
11 | ||
12 | config = lib.mkIf cfg.enable { | |
1a64deeb IB |
13 | myServices.dns.zones."immae.eu".subdomains.mastodon = |
14 | with config.myServices.dns.helpers; ips servers.eldiron.ips.main; | |
15 | ||
16 | myServices.chatonsProperties.services.mastodon = { | |
17 | file.datetime = "2022-08-21T19:50:00"; | |
18 | service = { | |
19 | name = "Mastodon"; | |
20 | description = "Your self-hosted, globally interconnected microblogging community"; | |
21 | website = "https://mastodon.immae.eu/"; | |
22 | logo = "https://mastodon.immae.eu/apple-touch-icon.png"; | |
23 | status.level = "OK"; | |
24 | status.description = "OK"; | |
25 | registration."" = ["MEMBER" "CLIENT"]; | |
26 | registration.load = "OPEN"; | |
27 | install.type = "PACKAGE"; | |
28 | }; | |
29 | software = { | |
30 | name = "Mastodon"; | |
31 | website = "https://joinmastodon.org/"; | |
32 | license.url = "https://github.com/tootsuite/mastodon/blob/master/LICENSE"; | |
33 | license.name = "GNU General Public License v3.0"; | |
34 | version = mcfg.package.version; | |
35 | source.url = "https://github.com/tootsuite/mastodon"; | |
36 | }; | |
37 | }; | |
4c4652aa | 38 | secrets.keys."webapps/tools-mastodon" = { |
eb14b976 IB |
39 | user = "mastodon"; |
40 | group = "mastodon"; | |
41 | permissions = "0400"; | |
42 | text = '' | |
43 | REDIS_HOST=${env.redis.host} | |
44 | REDIS_PORT=${env.redis.port} | |
45 | REDIS_DB=${env.redis.db} | |
46 | DB_HOST=${env.postgresql.socket} | |
47 | DB_USER=${env.postgresql.user} | |
48 | DB_NAME=${env.postgresql.database} | |
49 | DB_PASS=${env.postgresql.password} | |
50 | DB_PORT=${env.postgresql.port} | |
51 | ||
52 | LOCAL_DOMAIN=mastodon.immae.eu | |
53 | LOCAL_HTTPS=true | |
54 | ALTERNATE_DOMAINS=immae.eu | |
55 | ||
56 | PAPERCLIP_SECRET=${env.paperclip_secret} | |
57 | SECRET_KEY_BASE=${env.secret_key_base} | |
58 | OTP_SECRET=${env.otp_secret} | |
59 | ||
60 | VAPID_PRIVATE_KEY=${env.vapid.private} | |
61 | VAPID_PUBLIC_KEY=${env.vapid.public} | |
62 | ||
63 | SMTP_DELIVERY_METHOD=sendmail | |
64 | SMTP_FROM_ADDRESS=mastodon@tools.immae.eu | |
65 | SENDMAIL_LOCATION="/run/wrappers/bin/sendmail" | |
613aea56 | 66 | PAPERCLIP_ROOT_PATH=${mcfg.dataDir} |
eb14b976 IB |
67 | |
68 | STREAMING_CLUSTER_NUM=1 | |
69 | ||
70 | RAILS_LOG_LEVEL=warn | |
71 | ||
72 | # LDAP authentication (optional) | |
73 | LDAP_ENABLED=true | |
ab8f306d | 74 | LDAP_HOST=${env.ldap.host} |
eb14b976 IB |
75 | LDAP_PORT=636 |
76 | LDAP_METHOD=simple_tls | |
ab8f306d IB |
77 | LDAP_BASE="${env.ldap.base}" |
78 | LDAP_BIND_DN="${env.ldap.dn}" | |
eb14b976 IB |
79 | LDAP_PASSWORD="${env.ldap.password}" |
80 | LDAP_UID="uid" | |
ab8f306d | 81 | LDAP_SEARCH_FILTER="${env.ldap.filter}" |
eb14b976 | 82 | ''; |
4c4652aa | 83 | }; |
1a64deeb | 84 | immaeServices.mastodon = { |
613aea56 | 85 | enable = true; |
da30ae4f | 86 | configFile = config.secrets.fullPaths."webapps/tools-mastodon"; |
613aea56 IB |
87 | socketsPrefix = "live_immae"; |
88 | dataDir = "/var/lib/mastodon_immae"; | |
35a397cd | 89 | }; |
17f6eae9 IB |
90 | services.filesWatcher.mastodon-streaming = { |
91 | restart = true; | |
92 | paths = [ mcfg.configFile ]; | |
93 | }; | |
94 | services.filesWatcher.mastodon-web = { | |
95 | restart = true; | |
96 | paths = [ mcfg.configFile ]; | |
97 | }; | |
98 | services.filesWatcher.mastodon-sidekiq = { | |
99 | restart = true; | |
100 | paths = [ mcfg.configFile ]; | |
101 | }; | |
102 | ||
35a397cd | 103 | |
29f8cb85 | 104 | services.websites.env.tools.modules = [ |
a952acc4 | 105 | "headers" "proxy" "proxy_wstunnel" "proxy_http" |
35a397cd | 106 | ]; |
1a64deeb | 107 | security.acme.certs.eldiron.extraDomainNames = [ "mastodon.immae.eu" ]; |
29f8cb85 | 108 | services.websites.env.tools.vhostConfs.mastodon = { |
35a397cd IB |
109 | certName = "eldiron"; |
110 | hosts = ["mastodon.immae.eu" ]; | |
a95ab089 | 111 | root = root; |
35a397cd IB |
112 | extraConfig = [ '' |
113 | Header always set Referrer-Policy "strict-origin-when-cross-origin" | |
114 | Header always set Strict-Transport-Security "max-age=31536000" | |
115 | ||
116 | <LocationMatch "^/(assets|avatars|emoji|headers|packs|sounds|system)> | |
117 | Header always set Cache-Control "public, max-age=31536000, immutable" | |
118 | Require all granted | |
119 | </LocationMatch> | |
120 | ||
121 | ProxyPreserveHost On | |
122 | RequestHeader set X-Forwarded-Proto "https" | |
123 | ||
124 | RewriteEngine On | |
125 | ||
613aea56 | 126 | RewriteRule ^/api/v1/streaming/(.+)$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/$1 [P,NE,QSA,L] |
1a64deeb | 127 | RewriteRule ^/api/v1/streaming/public$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/public [P,NE,QSA,L] |
613aea56 | 128 | RewriteRule ^/api/v1/streaming/$ unix://${mcfg.sockets.node}|ws://mastodon.immae.eu/ [P,NE,QSA,L] |
1a64deeb IB |
129 | RewriteCond %{REQUEST_URI} !/500.html |
130 | RewriteCond %{REQUEST_URI} !/sw.js | |
131 | RewriteCond %{REQUEST_URI} !/embed.js | |
132 | RewriteCond %{REQUEST_URI} !/robots.txt | |
133 | RewriteCond %{REQUEST_URI} !/manifest.json | |
134 | RewriteCond %{REQUEST_URI} !/browserconfig.xml | |
135 | RewriteCond %{REQUEST_URI} !/mask-icon.svg | |
136 | RewriteCond %{REQUEST_URI} !^(/.*\.(png|ico|gif)$) | |
137 | RewriteCond %{REQUEST_URI} !^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge) | |
138 | RewriteRule ^/(.*)$ unix:///run/mastodon/live_immae_puma.sock|http://mastodon.immae.eu/$1 [P,NE,QSA,L] | |
613aea56 | 139 | ProxyPassReverse / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/ |
35a397cd | 140 | |
613aea56 | 141 | Alias /system ${mcfg.dataDir} |
35a397cd | 142 | |
613aea56 | 143 | <Directory ${mcfg.dataDir}> |
35a397cd IB |
144 | Require all granted |
145 | Options -MultiViews | |
146 | </Directory> | |
147 | ||
a95ab089 | 148 | <Directory ${root}> |
35a397cd IB |
149 | Require all granted |
150 | Options -MultiViews +FollowSymlinks | |
151 | </Directory> | |
152 | ||
153 | ErrorDocument 500 /500.html | |
154 | ErrorDocument 501 /500.html | |
155 | ErrorDocument 502 /500.html | |
156 | ErrorDocument 503 /500.html | |
157 | ErrorDocument 504 /500.html | |
158 | '' ]; | |
159 | }; | |
1a64deeb IB |
160 | myServices.monitoring.fromMasterActivatedPlugins = [ "http" ]; |
161 | myServices.monitoring.fromMasterObjects.service = [ | |
162 | { | |
163 | service_description = "mastodon website is running on mastodon.immae.eu"; | |
164 | host_name = config.hostEnv.fqdn; | |
165 | use = "external-web-service"; | |
166 | check_command = ["check_https" "mastodon.immae.eu" "/" "Mastodon</title>"]; | |
167 | ||
168 | servicegroups = "webstatus-webapps"; | |
169 | _webstatus_name = "Mastodon"; | |
170 | _webstatus_url = "https://mastodon.immae.eu/"; | |
171 | } | |
172 | ]; | |
35a397cd IB |
173 | }; |
174 | } |