]>
Commit | Line | Data |
---|---|---|
996a68c2 IB |
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 | fullPackage = cfg.package.withPlugins cfg.plugins; | |
10 | paste_local = pkgs.writeText "paste_local.ini" '' | |
11 | [DEFAULT] | |
12 | debug = false | |
13 | ||
14 | [pipeline:main] | |
15 | pipeline = mediagoblin | |
16 | ||
17 | [app:mediagoblin] | |
18 | use = egg:mediagoblin#app | |
19 | config = ${cfg.configFile} ${fullPackage}/mediagoblin.ini | |
20 | /mgoblin_static = ${fullPackage}/mediagoblin/static | |
21 | ||
22 | [loggers] | |
23 | keys = root | |
24 | ||
25 | [handlers] | |
26 | keys = console | |
27 | ||
28 | [formatters] | |
29 | keys = generic | |
30 | ||
31 | [logger_root] | |
32 | level = INFO | |
33 | handlers = console | |
34 | ||
35 | [handler_console] | |
36 | class = StreamHandler | |
37 | args = (sys.stderr,) | |
38 | level = NOTSET | |
39 | formatter = generic | |
40 | ||
41 | [formatter_generic] | |
42 | format = %(levelname)-7.7s [%(name)s] %(message)s | |
43 | ||
44 | [filter:errors] | |
45 | use = egg:mediagoblin#errors | |
46 | debug = false | |
47 | ||
48 | [server:main] | |
49 | use = egg:waitress#main | |
50 | unix_socket = ${cfg.socketsDir}/mediagoblin.sock | |
51 | unix_socket_perms = 777 | |
52 | url_scheme = https | |
53 | ''; | |
54 | in | |
55 | { | |
56 | options.services.mediagoblin = { | |
57 | enable = lib.mkEnableOption "Enable Mediagoblin’s service"; | |
58 | user = lib.mkOption { | |
59 | type = lib.types.str; | |
60 | default = name; | |
61 | description = "User account under which Mediagoblin runs"; | |
62 | }; | |
63 | group = lib.mkOption { | |
64 | type = lib.types.str; | |
65 | default = name; | |
66 | description = "Group under which Mediagoblin runs"; | |
67 | }; | |
68 | dataDir = lib.mkOption { | |
69 | type = lib.types.path; | |
70 | default = "/var/lib/${name}"; | |
71 | description = '' | |
72 | The directory where Mediagoblin stores its data. | |
73 | ''; | |
74 | }; | |
75 | socketsDir = lib.mkOption { | |
76 | type = lib.types.path; | |
77 | default = "/run/${name}"; | |
78 | description = '' | |
79 | The directory where Mediagoblin puts runtime files and sockets. | |
80 | ''; | |
81 | }; | |
82 | configFile = lib.mkOption { | |
83 | type = lib.types.path; | |
84 | description = '' | |
85 | The configuration file path for Mediagoblin. | |
86 | ''; | |
87 | }; | |
88 | package = lib.mkOption { | |
89 | type = lib.types.package; | |
90 | default = pkgs.webapps.mediagoblin; | |
91 | description = '' | |
92 | Mediagoblin package to use. | |
93 | ''; | |
94 | }; | |
95 | plugins = lib.mkOption { | |
96 | type = lib.types.listOf lib.types.package; | |
97 | default = []; | |
98 | description = '' | |
99 | Mediagoblin plugins to use. | |
100 | ''; | |
101 | }; | |
102 | }; | |
103 | ||
104 | config = lib.mkIf cfg.enable { | |
105 | users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton { | |
106 | inherit name; | |
107 | inherit uid; | |
108 | group = cfg.group; | |
109 | description = "Mediagoblin user"; | |
110 | home = cfg.dataDir; | |
111 | useDefaultShell = true; | |
112 | }); | |
113 | users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton { | |
114 | inherit name; | |
115 | inherit gid; | |
116 | }); | |
117 | ||
118 | systemd.services.mediagoblin-web = { | |
119 | description = "Mediagoblin service"; | |
120 | wantedBy = [ "multi-user.target" ]; | |
121 | after = [ "network.target" ]; | |
122 | wants = [ "postgresql.service" "redis.service" ]; | |
123 | ||
124 | environment.SCRIPT_NAME = "/mediagoblin/"; | |
125 | ||
126 | script = '' | |
127 | exec ./bin/paster serve \ | |
128 | ${paste_local} \ | |
129 | --pid-file=${cfg.socketsDir}/mediagoblin.pid | |
130 | ''; | |
131 | preStop = '' | |
132 | exec ./bin/paster serve \ | |
133 | --pid-file=${cfg.socketsDir}/mediagoblin.pid \ | |
134 | ${paste_local} stop | |
135 | ''; | |
136 | preStart = '' | |
137 | ./bin/gmg -cf ${cfg.configFile} dbupdate | |
138 | ''; | |
139 | ||
140 | serviceConfig = { | |
141 | User = cfg.user; | |
142 | PrivateTmp = true; | |
143 | Restart = "always"; | |
144 | TimeoutSec = 15; | |
145 | Type = "simple"; | |
146 | WorkingDirectory = fullPackage; | |
147 | PIDFile = "${cfg.socketsDir}/mediagoblin.pid"; | |
148 | }; | |
149 | ||
150 | unitConfig.RequiresMountsFor = cfg.dataDir; | |
151 | }; | |
152 | ||
153 | systemd.services.mediagoblin-celeryd = { | |
154 | description = "Mediagoblin service"; | |
155 | wantedBy = [ "multi-user.target" ]; | |
156 | after = [ "network.target" "mediagoblin-web.service" ]; | |
157 | ||
158 | environment.MEDIAGOBLIN_CONFIG = cfg.configFile; | |
159 | environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery"; | |
160 | ||
161 | script = '' | |
162 | exec ./bin/celery worker \ | |
163 | --logfile=${cfg.dataDir}/celery.log \ | |
164 | --loglevel=INFO | |
165 | ''; | |
166 | ||
167 | serviceConfig = { | |
168 | User = cfg.user; | |
169 | PrivateTmp = true; | |
170 | Restart = "always"; | |
171 | TimeoutSec = 60; | |
172 | Type = "simple"; | |
173 | WorkingDirectory = fullPackage; | |
174 | PIDFile = "${cfg.socketsDir}/mediagoblin-celeryd.pid"; | |
175 | }; | |
176 | ||
177 | unitConfig.RequiresMountsFor = cfg.dataDir; | |
178 | }; | |
179 | ||
180 | system.activationScripts.mediagoblin = { | |
181 | deps = [ "users" ]; | |
182 | text = '' | |
183 | install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.socketsDir} | |
184 | install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} | |
185 | if [ -d ${cfg.dataDir}/plugin_static/ ]; then | |
186 | rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth | |
187 | ln -sf ${fullPackage}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth | |
188 | fi | |
189 | ''; | |
190 | }; | |
191 | ||
192 | }; | |
193 | } |