1 { lib, pkgs, config, ... }:
4 cfg = config.services.mediagoblin;
6 uid = config.ids.uids.mediagoblin;
7 gid = config.ids.gids.mediagoblin;
9 fullPackage = cfg.package.withPlugins cfg.plugins;
10 paste_local = pkgs.writeText "paste_local.ini" ''
15 pipeline = mediagoblin
18 use = egg:mediagoblin#app
19 config = ${cfg.configFile} ${fullPackage}/mediagoblin.ini
20 /mgoblin_static = ${fullPackage}/mediagoblin/static
42 format = %(levelname)-7.7s [%(name)s] %(message)s
45 use = egg:mediagoblin#errors
49 use = egg:waitress#main
50 unix_socket = ${cfg.socketsDir}/mediagoblin.sock
51 unix_socket_perms = 777
56 options.services.mediagoblin = {
57 enable = lib.mkEnableOption "Enable Mediagoblin’s service";
61 description = "User account under which Mediagoblin runs";
63 group = lib.mkOption {
66 description = "Group under which Mediagoblin runs";
68 dataDir = lib.mkOption {
69 type = lib.types.path;
70 default = "/var/lib/${name}";
72 The directory where Mediagoblin stores its data.
75 socketsDir = lib.mkOption {
76 type = lib.types.path;
77 default = "/run/${name}";
79 The directory where Mediagoblin puts runtime files and sockets.
82 configFile = lib.mkOption {
83 type = lib.types.path;
85 The configuration file path for Mediagoblin.
88 package = lib.mkOption {
89 type = lib.types.package;
90 default = pkgs.webapps.mediagoblin;
92 Mediagoblin package to use.
95 plugins = lib.mkOption {
96 type = lib.types.listOf lib.types.package;
99 Mediagoblin plugins to use.
104 config = lib.mkIf cfg.enable {
105 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
109 description = "Mediagoblin user";
111 useDefaultShell = true;
113 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
118 systemd.services.mediagoblin-web = {
119 description = "Mediagoblin service";
120 wantedBy = [ "multi-user.target" ];
121 after = [ "network.target" ];
122 wants = [ "postgresql.service" "redis.service" ];
124 environment.SCRIPT_NAME = "/mediagoblin/";
127 exec ./bin/paster serve \
129 --pid-file=${cfg.socketsDir}/mediagoblin.pid
132 exec ./bin/paster serve \
133 --pid-file=${cfg.socketsDir}/mediagoblin.pid \
137 ./bin/gmg -cf ${cfg.configFile} dbupdate
146 WorkingDirectory = fullPackage;
147 PIDFile = "${cfg.socketsDir}/mediagoblin.pid";
150 unitConfig.RequiresMountsFor = cfg.dataDir;
153 systemd.services.mediagoblin-celeryd = {
154 description = "Mediagoblin service";
155 wantedBy = [ "multi-user.target" ];
156 after = [ "network.target" "mediagoblin-web.service" ];
158 environment.MEDIAGOBLIN_CONFIG = cfg.configFile;
159 environment.CELERY_CONFIG_MODULE = "mediagoblin.init.celery.from_celery";
162 exec ./bin/celery worker \
163 --logfile=${cfg.dataDir}/celery.log \
173 WorkingDirectory = fullPackage;
174 PIDFile = "${cfg.socketsDir}/mediagoblin-celeryd.pid";
177 unitConfig.RequiresMountsFor = cfg.dataDir;
180 system.activationScripts.mediagoblin = {
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