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.workdir}/mediagoblin.ini
19 /mgoblin_static = ${cfg.workdir}/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;
91 Mediagoblin package to use.
94 plugins = lib.mkOption {
95 type = lib.types.listOf lib.types.package;
98 Mediagoblin plugins to use.
102 workdir = lib.mkOption {
103 type = lib.types.package;
104 default = cfg.package.withPlugins cfg.plugins;
106 Adjusted Mediagoblin package with plugins
110 systemdStateDirectory = lib.mkOption {
111 type = lib.types.str;
112 # Use ReadWritePaths= instead if varDir is outside of /var/lib
113 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
114 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
116 Adjusted Mediagoblin data directory for systemd
120 systemdRuntimeDirectory = lib.mkOption {
121 type = lib.types.str;
122 # Use ReadWritePaths= instead if socketsDir is outside of /run
123 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
124 lib.strings.removePrefix "/run/" cfg.socketsDir;
126 Adjusted Mediagoblin sockets directory for systemd
130 sockets = lib.mkOption {
131 type = lib.types.attrsOf lib.types.path;
133 paster = "${cfg.socketsDir}/mediagoblin.sock";
140 pids = lib.mkOption {
141 type = lib.types.attrsOf lib.types.path;
143 paster = "${cfg.socketsDir}/mediagoblin.pid";
144 celery = "${cfg.socketsDir}/mediagoblin-celeryd.pid";
148 Mediagoblin pid files
153 config = lib.mkIf cfg.enable {
154 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
158 description = "Mediagoblin user";
160 useDefaultShell = true;
162 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
167 systemd.services.mediagoblin-web = {
168 description = "Mediagoblin service";
169 wantedBy = [ "multi-user.target" ];
170 after = [ "network.target" ];
171 wants = [ "postgresql.service" "redis.service" ];
173 environment.SCRIPT_NAME = "/mediagoblin/";
176 exec ./bin/paster serve \
178 --pid-file=${cfg.pids.paster}
181 exec ./bin/paster serve \
182 --pid-file=${cfg.pids.paster} \
186 if [ -d ${cfg.dataDir}/plugin_static/ ]; then
187 rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
188 ln -sf ${cfg.workdir}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
190 ./bin/gmg -cf ${cfg.configFile} dbupdate
199 WorkingDirectory = cfg.workdir;
200 RuntimeDirectory = cfg.systemdRuntimeDirectory;
201 StateDirectory= cfg.systemdStateDirectory;
202 PIDFile = cfg.pids.paster;
205 unitConfig.RequiresMountsFor = cfg.dataDir;
208 systemd.services.mediagoblin-celeryd = {
209 description = "Mediagoblin service";
210 wantedBy = [ "multi-user.target" ];
211 after = [ "network.target" "mediagoblin-web.service" ];
213 environment.MEDIAGOBLIN_CONFIG = cfg.configFile;
214 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
217 exec ./bin/celery worker \
218 --logfile=${cfg.dataDir}/celery.log \
228 WorkingDirectory = cfg.workdir;
229 RuntimeDirectory = cfg.systemdRuntimeDirectory;
230 StateDirectory= cfg.systemdStateDirectory;
231 PIDFile = cfg.pids.celery;
234 unitConfig.RequiresMountsFor = cfg.dataDir;