diff options
Diffstat (limited to 'modules/webapps/mediagoblin.nix')
-rw-r--r-- | modules/webapps/mediagoblin.nix | 231 |
1 files changed, 0 insertions, 231 deletions
diff --git a/modules/webapps/mediagoblin.nix b/modules/webapps/mediagoblin.nix deleted file mode 100644 index 3fe5e38..0000000 --- a/modules/webapps/mediagoblin.nix +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | { lib, pkgs, config, ... }: | ||
2 | let | ||
3 | name = "mediagoblin"; | ||
4 | cfg = config.services.mediagoblin; | ||
5 | |||
6 | uid = config.ids.uids.mediagoblin; | ||
7 | gid = config.ids.gids.mediagoblin; | ||
8 | |||
9 | paste_local = pkgs.writeText "paste_local.ini" '' | ||
10 | [DEFAULT] | ||
11 | debug = false | ||
12 | |||
13 | [pipeline:main] | ||
14 | pipeline = mediagoblin | ||
15 | |||
16 | [app:mediagoblin] | ||
17 | use = egg:mediagoblin#app | ||
18 | config = ${cfg.configFile} ${cfg.package}/mediagoblin.ini | ||
19 | /mgoblin_static = ${cfg.package}/mediagoblin/static | ||
20 | |||
21 | [loggers] | ||
22 | keys = root | ||
23 | |||
24 | [handlers] | ||
25 | keys = console | ||
26 | |||
27 | [formatters] | ||
28 | keys = generic | ||
29 | |||
30 | [logger_root] | ||
31 | level = INFO | ||
32 | handlers = console | ||
33 | |||
34 | [handler_console] | ||
35 | class = StreamHandler | ||
36 | args = (sys.stderr,) | ||
37 | level = NOTSET | ||
38 | formatter = generic | ||
39 | |||
40 | [formatter_generic] | ||
41 | format = %(levelname)-7.7s [%(name)s] %(message)s | ||
42 | |||
43 | [filter:errors] | ||
44 | use = egg:mediagoblin#errors | ||
45 | debug = false | ||
46 | |||
47 | [server:main] | ||
48 | use = egg:waitress#main | ||
49 | unix_socket = ${cfg.sockets.paster} | ||
50 | unix_socket_perms = 777 | ||
51 | url_scheme = https | ||
52 | ''; | ||
53 | in | ||
54 | { | ||
55 | options.services.mediagoblin = { | ||
56 | enable = lib.mkEnableOption "Enable Mediagoblin’s service"; | ||
57 | user = lib.mkOption { | ||
58 | type = lib.types.str; | ||
59 | default = name; | ||
60 | description = "User account under which Mediagoblin runs"; | ||
61 | }; | ||
62 | group = lib.mkOption { | ||
63 | type = lib.types.str; | ||
64 | default = name; | ||
65 | description = "Group under which Mediagoblin runs"; | ||
66 | }; | ||
67 | dataDir = lib.mkOption { | ||
68 | type = lib.types.path; | ||
69 | default = "/var/lib/${name}"; | ||
70 | description = '' | ||
71 | The directory where Mediagoblin stores its data. | ||
72 | ''; | ||
73 | }; | ||
74 | socketsDir = lib.mkOption { | ||
75 | type = lib.types.path; | ||
76 | default = "/run/${name}"; | ||
77 | description = '' | ||
78 | The directory where Mediagoblin puts runtime files and sockets. | ||
79 | ''; | ||
80 | }; | ||
81 | configFile = lib.mkOption { | ||
82 | type = lib.types.path; | ||
83 | description = '' | ||
84 | The configuration file path for Mediagoblin. | ||
85 | ''; | ||
86 | }; | ||
87 | package = lib.mkOption { | ||
88 | type = lib.types.package; | ||
89 | default = pkgs.webapps.mediagoblin; | ||
90 | example = lib.literalExample '' | ||
91 | pkgs.webapps.mediagoblin.withPlugins (p: [p.basicsearch]) | ||
92 | ''; | ||
93 | description = '' | ||
94 | Mediagoblin package to use. | ||
95 | ''; | ||
96 | }; | ||
97 | systemdStateDirectory = lib.mkOption { | ||
98 | type = lib.types.str; | ||
99 | # Use ReadWritePaths= instead if varDir is outside of /var/lib | ||
100 | default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir; | ||
101 | lib.strings.removePrefix "/var/lib/" cfg.dataDir; | ||
102 | description = '' | ||
103 | Adjusted Mediagoblin data directory for systemd | ||
104 | ''; | ||
105 | readOnly = true; | ||
106 | }; | ||
107 | systemdRuntimeDirectory = lib.mkOption { | ||
108 | type = lib.types.str; | ||
109 | # Use ReadWritePaths= instead if socketsDir is outside of /run | ||
110 | default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir; | ||
111 | lib.strings.removePrefix "/run/" cfg.socketsDir; | ||
112 | description = '' | ||
113 | Adjusted Mediagoblin sockets directory for systemd | ||
114 | ''; | ||
115 | readOnly = true; | ||
116 | }; | ||
117 | sockets = lib.mkOption { | ||
118 | type = lib.types.attrsOf lib.types.path; | ||
119 | default = { | ||
120 | paster = "${cfg.socketsDir}/mediagoblin.sock"; | ||
121 | }; | ||
122 | readOnly = true; | ||
123 | description = '' | ||
124 | Mediagoblin sockets | ||
125 | ''; | ||
126 | }; | ||
127 | pids = lib.mkOption { | ||
128 | type = lib.types.attrsOf lib.types.path; | ||
129 | default = { | ||
130 | paster = "${cfg.socketsDir}/mediagoblin.pid"; | ||
131 | celery = "${cfg.socketsDir}/mediagoblin-celeryd.pid"; | ||
132 | }; | ||
133 | readOnly = true; | ||
134 | description = '' | ||
135 | Mediagoblin pid files | ||
136 | ''; | ||
137 | }; | ||
138 | }; | ||
139 | |||
140 | config = lib.mkIf cfg.enable { | ||
141 | users.users = lib.optionalAttrs (cfg.user == name) { | ||
142 | "${name}" = { | ||
143 | inherit uid; | ||
144 | group = cfg.group; | ||
145 | description = "Mediagoblin user"; | ||
146 | home = cfg.dataDir; | ||
147 | useDefaultShell = true; | ||
148 | }; | ||
149 | }; | ||
150 | users.groups = lib.optionalAttrs (cfg.group == name) { | ||
151 | "${name}" = { | ||
152 | inherit gid; | ||
153 | }; | ||
154 | }; | ||
155 | |||
156 | systemd.slices.mediagoblin = { | ||
157 | description = "Mediagoblin slice"; | ||
158 | }; | ||
159 | systemd.services.mediagoblin-web = { | ||
160 | description = "Mediagoblin service"; | ||
161 | wantedBy = [ "multi-user.target" ]; | ||
162 | after = [ "network.target" ]; | ||
163 | wants = [ "postgresql.service" "redis.service" ]; | ||
164 | |||
165 | environment.SCRIPT_NAME = "/mediagoblin/"; | ||
166 | |||
167 | script = '' | ||
168 | exec ./bin/paster serve \ | ||
169 | ${paste_local} \ | ||
170 | --pid-file=${cfg.pids.paster} | ||
171 | ''; | ||
172 | preStop = '' | ||
173 | exec ./bin/paster serve \ | ||
174 | --pid-file=${cfg.pids.paster} \ | ||
175 | ${paste_local} stop | ||
176 | ''; | ||
177 | preStart = '' | ||
178 | if [ -d ${cfg.dataDir}/plugin_static/ ]; then | ||
179 | rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth | ||
180 | ln -sf ${cfg.package}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth | ||
181 | fi | ||
182 | ./bin/gmg -cf ${cfg.configFile} dbupdate | ||
183 | ''; | ||
184 | |||
185 | serviceConfig = { | ||
186 | Slice = "mediagoblin.slice"; | ||
187 | User = cfg.user; | ||
188 | PrivateTmp = true; | ||
189 | Restart = "always"; | ||
190 | TimeoutSec = 15; | ||
191 | Type = "simple"; | ||
192 | WorkingDirectory = cfg.package; | ||
193 | RuntimeDirectory = cfg.systemdRuntimeDirectory; | ||
194 | StateDirectory= cfg.systemdStateDirectory; | ||
195 | PIDFile = cfg.pids.paster; | ||
196 | }; | ||
197 | |||
198 | unitConfig.RequiresMountsFor = cfg.dataDir; | ||
199 | }; | ||
200 | |||
201 | systemd.services.mediagoblin-celeryd = { | ||
202 | description = "Mediagoblin service"; | ||
203 | wantedBy = [ "multi-user.target" ]; | ||
204 | after = [ "network.target" "mediagoblin-web.service" ]; | ||
205 | |||
206 | environment.MEDIAGOBLIN_CONFIG = cfg.configFile; | ||
207 | environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery"; | ||
208 | |||
209 | script = '' | ||
210 | exec ./bin/celery worker \ | ||
211 | --logfile=${cfg.dataDir}/celery.log \ | ||
212 | --loglevel=INFO | ||
213 | ''; | ||
214 | |||
215 | serviceConfig = { | ||
216 | Slice = "mediagoblin.slice"; | ||
217 | User = cfg.user; | ||
218 | PrivateTmp = true; | ||
219 | Restart = "always"; | ||
220 | TimeoutSec = 60; | ||
221 | Type = "simple"; | ||
222 | WorkingDirectory = cfg.package; | ||
223 | RuntimeDirectory = cfg.systemdRuntimeDirectory; | ||
224 | StateDirectory= cfg.systemdStateDirectory; | ||
225 | PIDFile = cfg.pids.celery; | ||
226 | }; | ||
227 | |||
228 | unitConfig.RequiresMountsFor = cfg.dataDir; | ||
229 | }; | ||
230 | }; | ||
231 | } | ||