aboutsummaryrefslogtreecommitdiff
path: root/nixops
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-10 19:05:02 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-10 19:05:02 +0200
commit613aea5685ad4c698386c374474d8853bb736503 (patch)
tree687d0d244891d3d51b647d339f23533ec654ea98 /nixops
parent1a7188052f235fb632700478fad0108e4306107d (diff)
downloadNix-613aea5685ad4c698386c374474d8853bb736503.tar.gz
Nix-613aea5685ad4c698386c374474d8853bb736503.tar.zst
Nix-613aea5685ad4c698386c374474d8853bb736503.zip
Move mastodon module outside of nixops
Diffstat (limited to 'nixops')
-rw-r--r--nixops/modules/websites/tools/mastodon.nix149
1 files changed, 14 insertions, 135 deletions
diff --git a/nixops/modules/websites/tools/mastodon.nix b/nixops/modules/websites/tools/mastodon.nix
index c461bec..4b9b73e 100644
--- a/nixops/modules/websites/tools/mastodon.nix
+++ b/nixops/modules/websites/tools/mastodon.nix
@@ -1,15 +1,9 @@
1{ lib, pkgs, config, myconfig, mylibs, ... }: 1{ lib, pkgs, config, myconfig, mylibs, ... }:
2let 2let
3 varDir = "/var/lib/mastodon_immae";
4 socketsDir = "/run/mastodon";
5 nodeSocket = "${socketsDir}/live_immae_node.sock";
6 railsSocket = "${socketsDir}/live_immae_puma.sock";
7
8 mastodon = pkgs.webapps.mastodon.override { inherit varDir; };
9
10 env = myconfig.env.tools.mastodon; 3 env = myconfig.env.tools.mastodon;
11 root = "/run/current-system/webapps/tools_mastodon"; 4 root = "/run/current-system/webapps/tools_mastodon";
12 cfg = config.services.myWebsites.tools.mastodon; 5 cfg = config.services.myWebsites.tools.mastodon;
6 mcfg = config.services.mastodon;
13in { 7in {
14 options.services.myWebsites.tools.mastodon = { 8 options.services.myWebsites.tools.mastodon = {
15 enable = lib.mkEnableOption "enable mastodon's website"; 9 enable = lib.mkEnableOption "enable mastodon's website";
@@ -45,7 +39,7 @@ in {
45 SMTP_DELIVERY_METHOD=sendmail 39 SMTP_DELIVERY_METHOD=sendmail
46 SMTP_FROM_ADDRESS=mastodon@tools.immae.eu 40 SMTP_FROM_ADDRESS=mastodon@tools.immae.eu
47 SENDMAIL_LOCATION="/run/wrappers/bin/sendmail" 41 SENDMAIL_LOCATION="/run/wrappers/bin/sendmail"
48 PAPERCLIP_ROOT_PATH=${varDir} 42 PAPERCLIP_ROOT_PATH=${mcfg.dataDir}
49 43
50 STREAMING_CLUSTER_NUM=1 44 STREAMING_CLUSTER_NUM=1
51 45
@@ -63,126 +57,11 @@ in {
63 LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))" 57 LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))"
64 ''; 58 '';
65 }]; 59 }];
66 ids.uids.mastodon = env.user.uid; 60 services.mastodon = {
67 ids.gids.mastodon = env.user.gid; 61 enable = true;
68 62 configFile = "/var/secrets/webapps/tools-mastodon";
69 users.users.mastodon = { 63 socketsPrefix = "live_immae";
70 name = "mastodon"; 64 dataDir = "/var/lib/mastodon_immae";
71 uid = config.ids.uids.mastodon;
72 group = "mastodon";
73 description = "Mastodon user";
74 home = varDir;
75 useDefaultShell = true;
76 };
77
78 users.groups.mastodon.gid = config.ids.gids.mastodon;
79
80 systemd.services.mastodon-streaming = {
81 description = "Mastodon Streaming";
82 wantedBy = [ "multi-user.target" ];
83 after = [ "network.target" "mastodon-web.service" ];
84
85 environment.NODE_ENV = "production";
86 environment.SOCKET = nodeSocket;
87
88 path = [ pkgs.nodejs pkgs.bashInteractive ];
89
90 script = ''
91 exec npm run start
92 '';
93
94 postStart = ''
95 while [ ! -S $SOCKET ]; do
96 sleep 0.5
97 done
98 chmod a+w $SOCKET
99 '';
100
101 postStop = ''
102 rm $SOCKET
103 '';
104
105 serviceConfig = {
106 User = "mastodon";
107 EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
108 PrivateTmp = true;
109 Restart = "always";
110 TimeoutSec = 15;
111 Type = "simple";
112 WorkingDirectory = mastodon;
113 };
114
115 unitConfig.RequiresMountsFor = varDir;
116 };
117
118 systemd.services.mastodon-web = {
119 description = "Mastodon Web app";
120 wantedBy = [ "multi-user.target" ];
121 after = [ "network.target" ];
122
123 environment.RAILS_ENV = "production";
124 environment.BUNDLE_PATH = "${mastodon.gems}/${mastodon.gems.ruby.gemPath}";
125 environment.BUNDLE_GEMFILE = "${mastodon.gems.confFiles}/Gemfile";
126 environment.SOCKET = railsSocket;
127
128 path = [ mastodon.gems mastodon.gems.ruby pkgs.file ];
129
130 preStart = ''
131 ./bin/bundle exec rails db:migrate
132 '';
133
134 script = ''
135 exec ./bin/bundle exec puma -C config/puma.rb
136 '';
137
138 serviceConfig = {
139 User = "mastodon";
140 EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
141 PrivateTmp = true;
142 Restart = "always";
143 TimeoutSec = 60;
144 Type = "simple";
145 WorkingDirectory = mastodon;
146 };
147
148 unitConfig.RequiresMountsFor = varDir;
149 };
150
151 systemd.services.mastodon-sidekiq = {
152 description = "Mastodon Sidekiq";
153 wantedBy = [ "multi-user.target" ];
154 after = [ "network.target" "mastodon-web.service" ];
155
156 environment.RAILS_ENV="production";
157 environment.BUNDLE_PATH = "${mastodon.gems}/${mastodon.gems.ruby.gemPath}";
158 environment.BUNDLE_GEMFILE = "${mastodon.gems.confFiles}/Gemfile";
159 environment.DB_POOL="5";
160
161 path = [ mastodon.gems mastodon.gems.ruby pkgs.imagemagick pkgs.ffmpeg pkgs.file ];
162
163 script = ''
164 exec ./bin/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
165 '';
166
167 serviceConfig = {
168 User = "mastodon";
169 EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
170 PrivateTmp = true;
171 Restart = "always";
172 TimeoutSec = 15;
173 Type = "simple";
174 WorkingDirectory = mastodon;
175 };
176
177 unitConfig.RequiresMountsFor = varDir;
178 };
179
180 system.activationScripts.mastodon = {
181 deps = [ "users" ];
182 text = ''
183 install -m 0755 -o mastodon -g mastodon -d ${socketsDir}
184 install -m 0755 -o mastodon -g mastodon -d ${varDir} ${varDir}/tmp/cache
185 '';
186 }; 65 };
187 66
188 services.myWebsites.tools.modules = [ 67 services.myWebsites.tools.modules = [
@@ -191,7 +70,7 @@ in {
191 security.acme.certs."eldiron".extraDomains."mastodon.immae.eu" = null; 70 security.acme.certs."eldiron".extraDomains."mastodon.immae.eu" = null;
192 system.extraSystemBuilderCmds = '' 71 system.extraSystemBuilderCmds = ''
193 mkdir -p $out/webapps 72 mkdir -p $out/webapps
194 ln -s ${mastodon}/public/ $out/webapps/tools_mastodon 73 ln -s ${mcfg.workdir}/public/ $out/webapps/tools_mastodon
195 ''; 74 '';
196 services.myWebsites.tools.vhostConfs.mastodon = { 75 services.myWebsites.tools.vhostConfs.mastodon = {
197 certName = "eldiron"; 76 certName = "eldiron";
@@ -221,14 +100,14 @@ in {
221 ProxyPassMatch ^(/.*\.(png|ico|gif)$) ! 100 ProxyPassMatch ^(/.*\.(png|ico|gif)$) !
222 ProxyPassMatch ^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge) ! 101 ProxyPassMatch ^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge) !
223 102
224 RewriteRule ^/api/v1/streaming/(.+)$ unix://${nodeSocket}|http://mastodon.immae.eu/api/v1/streaming/$1 [P,NE,QSA,L] 103 RewriteRule ^/api/v1/streaming/(.+)$ unix://${mcfg.sockets.node}|http://mastodon.immae.eu/api/v1/streaming/$1 [P,NE,QSA,L]
225 RewriteRule ^/api/v1/streaming/$ unix://${nodeSocket}|ws://mastodon.immae.eu/ [P,NE,QSA,L] 104 RewriteRule ^/api/v1/streaming/$ unix://${mcfg.sockets.node}|ws://mastodon.immae.eu/ [P,NE,QSA,L]
226 ProxyPass / unix://${railsSocket}|http://mastodon.immae.eu/ 105 ProxyPass / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/
227 ProxyPassReverse / unix://${railsSocket}|http://mastodon.immae.eu/ 106 ProxyPassReverse / unix://${mcfg.sockets.rails}|http://mastodon.immae.eu/
228 107
229 Alias /system ${varDir} 108 Alias /system ${mcfg.dataDir}
230 109
231 <Directory ${varDir}> 110 <Directory ${mcfg.dataDir}>
232 Require all granted 111 Require all granted
233 Options -MultiViews 112 Options -MultiViews
234 </Directory> 113 </Directory>