aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-10 14:04:21 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-10 14:34:43 +0200
commit996a68c2ec15260dd0c6e8d3d60460e32571d3b7 (patch)
treefce778285407b5898fe00958646152baf30f50c2 /nixops/modules/websites
parent0f3009993afc4e88ff728226cf6edc15db3ab415 (diff)
downloadNix-996a68c2ec15260dd0c6e8d3d60460e32571d3b7.tar.gz
Nix-996a68c2ec15260dd0c6e8d3d60460e32571d3b7.tar.zst
Nix-996a68c2ec15260dd0c6e8d3d60460e32571d3b7.zip
Move Mediagoblin module outside of nixops
Diffstat (limited to 'nixops/modules/websites')
-rw-r--r--nixops/modules/websites/tools/mediagoblin.nix159
1 files changed, 15 insertions, 144 deletions
diff --git a/nixops/modules/websites/tools/mediagoblin.nix b/nixops/modules/websites/tools/mediagoblin.nix
index 2b56007..bdb8323 100644
--- a/nixops/modules/websites/tools/mediagoblin.nix
+++ b/nixops/modules/websites/tools/mediagoblin.nix
@@ -1,55 +1,8 @@
1{ lib, pkgs, config, myconfig, mylibs, ... }: 1{ lib, pkgs, config, myconfig, mylibs, ... }:
2let 2let
3 env = myconfig.env.tools.mediagoblin; 3 env = myconfig.env.tools.mediagoblin;
4 socketsDir = "/run/mediagoblin";
5 varDir = "/var/lib/mediagoblin";
6 cfg = config.services.myWebsites.tools.mediagoblin; 4 cfg = config.services.myWebsites.tools.mediagoblin;
7 mediagoblin_init = "/var/secrets/webapps/tools-mediagoblin"; 5 mcfg = config.services.mediagoblin;
8 paste_local = pkgs.writeText "paste_local.ini" ''
9 [DEFAULT]
10 debug = false
11
12 [pipeline:main]
13 pipeline = mediagoblin
14
15 [app:mediagoblin]
16 use = egg:mediagoblin#app
17 config = ${mediagoblin_init} ${pythonRoot}/mediagoblin.ini
18 /mgoblin_static = ${pythonRoot}/mediagoblin/static
19
20 [loggers]
21 keys = root
22
23 [handlers]
24 keys = console
25
26 [formatters]
27 keys = generic
28
29 [logger_root]
30 level = INFO
31 handlers = console
32
33 [handler_console]
34 class = StreamHandler
35 args = (sys.stderr,)
36 level = NOTSET
37 formatter = generic
38
39 [formatter_generic]
40 format = %(levelname)-7.7s [%(name)s] %(message)s
41
42 [filter:errors]
43 use = egg:mediagoblin#errors
44 debug = false
45
46 [server:main]
47 use = egg:waitress#main
48 unix_socket = ${socketsDir}/mediagoblin.sock
49 unix_socket_perms = 777
50 url_scheme = https
51 '';
52 pythonRoot = pkgs.webapps.mediagoblin-with-plugins;
53in { 6in {
54 options.services.myWebsites.tools.mediagoblin = { 7 options.services.myWebsites.tools.mediagoblin = {
55 enable = lib.mkEnableOption "enable mediagoblin's website"; 8 enable = lib.mkEnableOption "enable mediagoblin's website";
@@ -63,7 +16,7 @@ in {
63 permissions = "0400"; 16 permissions = "0400";
64 text = '' 17 text = ''
65 [DEFAULT] 18 [DEFAULT]
66 data_basedir = "${varDir}" 19 data_basedir = "${mcfg.dataDir}"
67 20
68 [mediagoblin] 21 [mediagoblin]
69 direct_remote_path = /mgoblin_static/ 22 direct_remote_path = /mgoblin_static/
@@ -118,94 +71,12 @@ in {
118 ''; 71 '';
119 }]; 72 }];
120 73
121 ids.uids.mediagoblin = myconfig.env.tools.mediagoblin.user.uid; 74 users.users.mediagoblin.extraGroups = [ "keys" ];
122 ids.gids.mediagoblin = myconfig.env.tools.mediagoblin.user.gid;
123 75
124 users.users.mediagoblin = { 76 services.mediagoblin = {
125 name = "mediagoblin"; 77 enable = true;
126 uid = config.ids.uids.mediagoblin; 78 plugins = builtins.attrValues pkgs.webapps.mediagoblin-plugins;
127 group = "mediagoblin"; 79 configFile = "/var/secrets/webapps/tools-mediagoblin";
128 description = "Mediagoblin user";
129 home = varDir;
130 useDefaultShell = true;
131 extraGroups = [ "keys" ];
132 };
133
134 users.groups.mediagoblin.gid = config.ids.gids.mediagoblin;
135
136 systemd.services.mediagoblin-web = {
137 description = "Mediagoblin service";
138 wantedBy = [ "multi-user.target" ];
139 after = [ "network.target" ];
140 wants = [ "postgresql.service" "redis.service" ];
141
142 environment.SCRIPT_NAME = "/mediagoblin/";
143
144 script = ''
145 exec ./bin/paster serve \
146 ${paste_local} \
147 --pid-file=${socketsDir}/mediagoblin.pid
148 '';
149
150 preStop = ''
151 exec ./bin/paster serve \
152 --pid-file=${socketsDir}/mediagoblin.pid \
153 ${paste_local} stop
154 '';
155 preStart = ''
156 ./bin/gmg -cf ${mediagoblin_init} dbupdate
157 '';
158
159 serviceConfig = {
160 User = "mediagoblin";
161 PrivateTmp = true;
162 Restart = "always";
163 TimeoutSec = 15;
164 Type = "simple";
165 WorkingDirectory = pythonRoot;
166 PIDFile = "${socketsDir}/mediagoblin.pid";
167 };
168
169 unitConfig.RequiresMountsFor = varDir;
170 };
171
172 systemd.services.mediagoblin-celeryd = {
173 description = "Mediagoblin service";
174 wantedBy = [ "multi-user.target" ];
175 after = [ "network.target" "mediagoblin-web.service" ];
176
177 environment.MEDIAGOBLIN_CONFIG = mediagoblin_init;
178 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
179
180 script = ''
181 exec ./bin/celery worker \
182 --logfile=${varDir}/celery.log \
183 --loglevel=INFO
184 '';
185
186 serviceConfig = {
187 User = "mediagoblin";
188 PrivateTmp = true;
189 Restart = "always";
190 TimeoutSec = 60;
191 Type = "simple";
192 WorkingDirectory = pythonRoot;
193 PIDFile = "${socketsDir}/mediagoblin-celeryd.pid";
194 };
195
196 unitConfig.RequiresMountsFor = varDir;
197 };
198
199 system.activationScripts.mediagoblin = {
200 deps = [ "users" ];
201 text = ''
202 install -m 0755 -o mediagoblin -g mediagoblin -d ${socketsDir}
203 install -m 0755 -o mediagoblin -g mediagoblin -d ${varDir}
204 if [ -d ${varDir}/plugin_static/ ]; then
205 rm ${varDir}/plugin_static/coreplugin_basic_auth
206 ln -sf ${pythonRoot}/mediagoblin/plugins/basic_auth/static ${varDir}/plugin_static/coreplugin_basic_auth
207 fi
208 '';
209 }; 80 };
210 81
211 services.myWebsites.tools.modules = [ 82 services.myWebsites.tools.modules = [
@@ -218,20 +89,20 @@ in {
218 hosts = ["mgoblin.immae.eu" ]; 89 hosts = ["mgoblin.immae.eu" ];
219 root = null; 90 root = null;
220 extraConfig = [ '' 91 extraConfig = [ ''
221 Alias /mgoblin_media ${varDir}/media/public 92 Alias /mgoblin_media ${mcfg.dataDir}/media/public
222 <Directory ${varDir}/media/public> 93 <Directory ${mcfg.dataDir}/media/public>
223 Options -Indexes +FollowSymLinks +MultiViews +Includes 94 Options -Indexes +FollowSymLinks +MultiViews +Includes
224 Require all granted 95 Require all granted
225 </Directory> 96 </Directory>
226 97
227 Alias /theme_static ${varDir}/theme_static 98 Alias /theme_static ${mcfg.dataDir}/theme_static
228 <Directory ${varDir}/theme_static> 99 <Directory ${mcfg.dataDir}/theme_static>
229 Options -Indexes +FollowSymLinks +MultiViews +Includes 100 Options -Indexes +FollowSymLinks +MultiViews +Includes
230 Require all granted 101 Require all granted
231 </Directory> 102 </Directory>
232 103
233 Alias /plugin_static ${varDir}/plugin_static 104 Alias /plugin_static ${mcfg.dataDir}/plugin_static
234 <Directory ${varDir}/plugin_static> 105 <Directory ${mcfg.dataDir}/plugin_static>
235 Options -Indexes +FollowSymLinks +MultiViews +Includes 106 Options -Indexes +FollowSymLinks +MultiViews +Includes
236 Require all granted 107 Require all granted
237 </Directory> 108 </Directory>
@@ -243,8 +114,8 @@ in {
243 ProxyPass /theme_static ! 114 ProxyPass /theme_static !
244 ProxyPass /plugin_static ! 115 ProxyPass /plugin_static !
245 ProxyPassMatch ^/.well-known/acme-challenge ! 116 ProxyPassMatch ^/.well-known/acme-challenge !
246 ProxyPass / unix://${socketsDir}/mediagoblin.sock|http://mgoblin.immae.eu/ 117 ProxyPass / unix://${mcfg.socketsDir}/mediagoblin.sock|http://mgoblin.immae.eu/
247 ProxyPassReverse / unix://${socketsDir}/mediagoblin.sock|http://mgoblin.immae.eu/ 118 ProxyPassReverse / unix://${mcfg.socketsDir}/mediagoblin.sock|http://mgoblin.immae.eu/
248 '' ]; 119 '' ];
249 }; 120 };
250 }; 121 };