1 { lib, pkgs, config, ... }:
4 cfg = config.services.mediagoblin;
6 uid = config.ids.uids.mediagoblin;
7 gid = config.ids.gids.mediagoblin;
9 paste_local = pkgs.writeText "paste_local.ini" ''
14 pipeline = mediagoblin
17 use = egg:mediagoblin#app
18 config = ${cfg.configFile} ${cfg.package}/mediagoblin.ini
19 /mgoblin_static = ${cfg.package}/mediagoblin/static
41 format = %(levelname)-7.7s [%(name)s] %(message)s
44 use = egg:mediagoblin#errors
48 use = egg:waitress#main
49 unix_socket = ${cfg.sockets.paster}
50 unix_socket_perms = 777
55 options.services.mediagoblin = {
56 enable = lib.mkEnableOption "Enable Mediagoblin’s service";
60 description = "User account under which Mediagoblin runs";
62 group = lib.mkOption {
65 description = "Group under which Mediagoblin runs";
67 dataDir = lib.mkOption {
68 type = lib.types.path;
69 default = "/var/lib/${name}";
71 The directory where Mediagoblin stores its data.
74 socketsDir = lib.mkOption {
75 type = lib.types.path;
76 default = "/run/${name}";
78 The directory where Mediagoblin puts runtime files and sockets.
81 configFile = lib.mkOption {
82 type = lib.types.path;
84 The configuration file path for Mediagoblin.
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])
94 Mediagoblin package to use.
97 systemdStateDirectory = lib.mkOption {
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;
103 Adjusted Mediagoblin data directory for systemd
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;
113 Adjusted Mediagoblin sockets directory for systemd
117 sockets = lib.mkOption {
118 type = lib.types.attrsOf lib.types.path;
120 paster = "${cfg.socketsDir}/mediagoblin.sock";
127 pids = lib.mkOption {
128 type = lib.types.attrsOf lib.types.path;
130 paster = "${cfg.socketsDir}/mediagoblin.pid";
131 celery = "${cfg.socketsDir}/mediagoblin-celeryd.pid";
135 Mediagoblin pid files
140 config = lib.mkIf cfg.enable {
141 users.users = lib.optionalAttrs (cfg.user == name) {
145 description = "Mediagoblin user";
147 useDefaultShell = true;
150 users.groups = lib.optionalAttrs (cfg.group == name) {
156 systemd.services.mediagoblin-web = {
157 description = "Mediagoblin service";
158 wantedBy = [ "multi-user.target" ];
159 after = [ "network.target" ];
160 wants = [ "postgresql.service" "redis.service" ];
162 environment.SCRIPT_NAME = "/mediagoblin/";
165 exec ./bin/paster serve \
167 --pid-file=${cfg.pids.paster}
170 exec ./bin/paster serve \
171 --pid-file=${cfg.pids.paster} \
175 if [ -d ${cfg.dataDir}/plugin_static/ ]; then
176 rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
177 ln -sf ${cfg.package}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
179 ./bin/gmg -cf ${cfg.configFile} dbupdate
188 WorkingDirectory = cfg.package;
189 RuntimeDirectory = cfg.systemdRuntimeDirectory;
190 StateDirectory= cfg.systemdStateDirectory;
191 PIDFile = cfg.pids.paster;
194 unitConfig.RequiresMountsFor = cfg.dataDir;
197 systemd.services.mediagoblin-celeryd = {
198 description = "Mediagoblin service";
199 wantedBy = [ "multi-user.target" ];
200 after = [ "network.target" "mediagoblin-web.service" ];
202 environment.MEDIAGOBLIN_CONFIG = cfg.configFile;
203 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
206 exec ./bin/celery worker \
207 --logfile=${cfg.dataDir}/celery.log \
217 WorkingDirectory = cfg.package;
218 RuntimeDirectory = cfg.systemdRuntimeDirectory;
219 StateDirectory= cfg.systemdStateDirectory;
220 PIDFile = cfg.pids.celery;
223 unitConfig.RequiresMountsFor = cfg.dataDir;