]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/tools/mastodon/default.nix
Use attrs for secrets instead of lists
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / mastodon / default.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
35a397cd 2let
ab8f306d 3 env = config.myEnv.tools.mastodon;
a95ab089 4 root = "/run/current-system/webapps/tools_mastodon";
4288c2f2 5 cfg = config.myServices.websites.tools.mastodon;
613aea56 6 mcfg = config.services.mastodon;
35a397cd 7in {
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 {
d2e703c5 13 services.duplyBackup.profiles.mastodon = {
6a8252b1
IB
14 rootDir = mcfg.dataDir;
15 };
4c4652aa 16 secrets.keys."webapps/tools-mastodon" = {
eb14b976
IB
17 user = "mastodon";
18 group = "mastodon";
19 permissions = "0400";
20 text = ''
21 REDIS_HOST=${env.redis.host}
22 REDIS_PORT=${env.redis.port}
23 REDIS_DB=${env.redis.db}
24 DB_HOST=${env.postgresql.socket}
25 DB_USER=${env.postgresql.user}
26 DB_NAME=${env.postgresql.database}
27 DB_PASS=${env.postgresql.password}
28 DB_PORT=${env.postgresql.port}
29
30 LOCAL_DOMAIN=mastodon.immae.eu
31 LOCAL_HTTPS=true
32 ALTERNATE_DOMAINS=immae.eu
33
34 PAPERCLIP_SECRET=${env.paperclip_secret}
35 SECRET_KEY_BASE=${env.secret_key_base}
36 OTP_SECRET=${env.otp_secret}
37
38 VAPID_PRIVATE_KEY=${env.vapid.private}
39 VAPID_PUBLIC_KEY=${env.vapid.public}
40
41 SMTP_DELIVERY_METHOD=sendmail
42 SMTP_FROM_ADDRESS=mastodon@tools.immae.eu
43 SENDMAIL_LOCATION="/run/wrappers/bin/sendmail"
613aea56 44 PAPERCLIP_ROOT_PATH=${mcfg.dataDir}
eb14b976
IB
45
46 STREAMING_CLUSTER_NUM=1
47
48 RAILS_LOG_LEVEL=warn
49
50 # LDAP authentication (optional)
51 LDAP_ENABLED=true
ab8f306d 52 LDAP_HOST=${env.ldap.host}
eb14b976
IB
53 LDAP_PORT=636
54 LDAP_METHOD=simple_tls
ab8f306d
IB
55 LDAP_BASE="${env.ldap.base}"
56 LDAP_BIND_DN="${env.ldap.dn}"
eb14b976
IB
57 LDAP_PASSWORD="${env.ldap.password}"
58 LDAP_UID="uid"
ab8f306d 59 LDAP_SEARCH_FILTER="${env.ldap.filter}"
eb14b976 60 '';
4c4652aa 61 };
613aea56
IB
62 services.mastodon = {
63 enable = true;
da30ae4f 64 configFile = config.secrets.fullPaths."webapps/tools-mastodon";
613aea56
IB
65 socketsPrefix = "live_immae";
66 dataDir = "/var/lib/mastodon_immae";
35a397cd 67 };
17f6eae9
IB
68 services.filesWatcher.mastodon-streaming = {
69 restart = true;
70 paths = [ mcfg.configFile ];
71 };
72 services.filesWatcher.mastodon-web = {
73 restart = true;
74 paths = [ mcfg.configFile ];
75 };
76 services.filesWatcher.mastodon-sidekiq = {
77 restart = true;
78 paths = [ mcfg.configFile ];
79 };
80
35a397cd 81
29f8cb85 82 services.websites.env.tools.modules = [
a952acc4 83 "headers" "proxy" "proxy_wstunnel" "proxy_http"
35a397cd 84 ];
a95ab089
IB
85 system.extraSystemBuilderCmds = ''
86 mkdir -p $out/webapps
613aea56 87 ln -s ${mcfg.workdir}/public/ $out/webapps/tools_mastodon
a95ab089 88 '';
29f8cb85 89 services.websites.env.tools.vhostConfs.mastodon = {
35a397cd 90 certName = "eldiron";
7df420c2 91 addToCerts = true;
35a397cd 92 hosts = ["mastodon.immae.eu" ];
a95ab089 93 root = root;
35a397cd
IB
94 extraConfig = [ ''
95 Header always set Referrer-Policy "strict-origin-when-cross-origin"
96 Header always set Strict-Transport-Security "max-age=31536000"
97
98 <LocationMatch "^/(assets|avatars|emoji|headers|packs|sounds|system)>
99 Header always set Cache-Control "public, max-age=31536000, immutable"
100 Require all granted
101 </LocationMatch>
102
103 ProxyPreserveHost On
104 RequestHeader set X-Forwarded-Proto "https"
105
106 RewriteEngine On
107
108 ProxyPass /500.html !
109 ProxyPass /sw.js !
110 ProxyPass /embed.js !
111 ProxyPass /robots.txt !
112 ProxyPass /manifest.json !
113 ProxyPass /browserconfig.xml !
114 ProxyPass /mask-icon.svg !
115 ProxyPassMatch ^(/.*\.(png|ico|gif)$) !
116 ProxyPassMatch ^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge) !
117
613aea56
IB
118 RewriteRule ^/api/v1/streaming/(.+)$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/$1 [P,NE,QSA,L]
119 RewriteRule ^/api/v1/streaming/$ unix://${mcfg.sockets.node}|ws://mastodon.immae.eu/ [P,NE,QSA,L]
120 ProxyPass / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/
121 ProxyPassReverse / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/
35a397cd 122
613aea56 123 Alias /system ${mcfg.dataDir}
35a397cd 124
613aea56 125 <Directory ${mcfg.dataDir}>
35a397cd
IB
126 Require all granted
127 Options -MultiViews
128 </Directory>
129
a95ab089 130 <Directory ${root}>
35a397cd
IB
131 Require all granted
132 Options -MultiViews +FollowSymlinks
133 </Directory>
134
135 ErrorDocument 500 /500.html
136 ErrorDocument 501 /500.html
137 ErrorDocument 502 /500.html
138 ErrorDocument 503 /500.html
139 ErrorDocument 504 /500.html
140 '' ];
141 };
142 };
143}