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 sockets = lib.mkOption {
111 type = lib.types.attrsOf lib.types.path;
113 paster = "${cfg.socketsDir}/mediagoblin.sock";
120 pids = lib.mkOption {
121 type = lib.types.attrsOf lib.types.path;
123 paster = "${cfg.socketsDir}/mediagoblin.pid";
124 celery = "${cfg.socketsDir}/mediagoblin-celeryd.pid";
128 Mediagoblin pid files
133 config = lib.mkIf cfg.enable {
134 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
138 description = "Mediagoblin user";
140 useDefaultShell = true;
142 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
147 systemd.services.mediagoblin-web = {
148 description = "Mediagoblin service";
149 wantedBy = [ "multi-user.target" ];
150 after = [ "network.target" ];
151 wants = [ "postgresql.service" "redis.service" ];
153 environment.SCRIPT_NAME = "/mediagoblin/";
156 exec ./bin/paster serve \
158 --pid-file=${cfg.pids.paster}
161 exec ./bin/paster serve \
162 --pid-file=${cfg.pids.paster} \
166 ./bin/gmg -cf ${cfg.configFile} dbupdate
175 WorkingDirectory = cfg.workdir;
176 PIDFile = cfg.pids.paster;
179 unitConfig.RequiresMountsFor = cfg.dataDir;
182 systemd.services.mediagoblin-celeryd = {
183 description = "Mediagoblin service";
184 wantedBy = [ "multi-user.target" ];
185 after = [ "network.target" "mediagoblin-web.service" ];
187 environment.MEDIAGOBLIN_CONFIG = cfg.configFile;
188 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
191 exec ./bin/celery worker \
192 --logfile=${cfg.dataDir}/celery.log \
202 WorkingDirectory = cfg.workdir;
203 PIDFile = cfg.pids.celery;
206 unitConfig.RequiresMountsFor = cfg.dataDir;
209 system.activationScripts.mediagoblin = {
212 install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.socketsDir}
213 install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
214 if [ -d ${cfg.dataDir}/plugin_static/ ]; then
215 rm ${cfg.dataDir}/plugin_static/coreplugin_basic_auth
216 ln -sf ${cfg.workdir}/mediagoblin/plugins/basic_auth/static ${cfg.dataDir}/plugin_static/coreplugin_basic_auth