@@ -0,0 +1,258 @@
1+{ config, lib, pkgs, ... }:
6+ cfg = config.services.mwlib;
7+ pypkgs = pkgs.python27Packages;
9+ inherit (pypkgs) python mwlib;
14+ description = "User to run as.";
20+ options.services.mwlib = {
27+ Whether to enable nserve. Nserve is a HTTP
28+ server. The Collection extension is talking to
29+ that program directly. Nserve uses at least
30+ one qserve instance in order to distribute
38+ description = "Specify port to listen on.";
42+ default = "127.0.0.1";
44+ description = "Specify network interface to listen on.";
48+ default = [ "${cfg.qserve.address}:${toString cfg.qserve.port}" ];
49+ type = types.listOf types.str;
50+ description = "Register qserve instance.";
61+ A job queue server used to distribute and manage
62+ jobs. You should start one qserve instance
63+ for each machine that is supposed to render pdf
64+ files. Unless you’re operating the Wikipedia
65+ installation, one machine should suffice.
72+ description = "Specify port to listen on.";
76+ default = "127.0.0.1";
78+ description = "Specify network interface to listen on.";
82+ default = "/var/lib/mwlib-qserve";
84+ description = "qserve data directory (FIXME: unused?)";
88+ default = [ "127.0.0.1" ];
89+ type = types.listOf types.str;
90+ description = "List of allowed client IPs. Empty means any.";
98+ default = cfg.qserve.enable;
101+ Pulls new jobs from exactly one qserve instance
102+ and calls the zip and render programs
103+ in order to download article collections and
104+ convert them to different output formats. Nslave
105+ uses a cache directory to store the generated
106+ documents. Nslave also starts an internal http
107+ server serving the content of the cache directory.
111+ cachedir = mkOption {
112+ default = "/var/cache/mwlib-nslave";
114+ description = "Directory to store generated documents.";
115+ }; # nslave.cachedir
117+ numprocs = mkOption {
120+ description = "Number of parallel jobs to be executed.";
121+ }; # nslave.numprocs
126+ Internal http server serving the content of the cache directory.
127+ You have to enable it, or use your own way for serving files
128+ and set the http.url option accordingly.
130+ type = types.submodule ({
135+ description = "Enable internal http server.";
136+ }; # nslave.http.enable
141+ description = "Port to listen to when serving files from cache.";
142+ }; # nslave.http.port
144+ address = mkOption {
145+ default = "127.0.0.1";
147+ description = "Specify network interface to listen on.";
148+ }; # nslave.http.address
151+ default = "http://localhost:${toString cfg.nslave.http.port}/cache";
154+ Specify URL for accessing generated files from cache.
155+ The Collection extension of Mediawiki won't be able to
156+ download files without it.
158+ }; # nslave.http.url
160+ }); # types.submodule
166+ }; # options.services
170+ systemd.services.mwlib-nserve = mkIf cfg.nserve.enable
172+ description = "mwlib network interface";
174+ wantedBy = [ "multi-user.target" ];
175+ after = [ "network.target" "mwlib-qserve.service" ];
178+ ExecStart = concatStringsSep " " (
180+ "${mwlib}/bin/nserve"
181+ "--port ${toString cfg.nserve.port}"
182+ "--interface ${cfg.nserve.address}"
183+ ] ++ cfg.nserve.qserve
185+ User = cfg.nserve.user;
187+ }; # systemd.services.mwlib-nserve
189+ systemd.services.mwlib-qserve = mkIf cfg.qserve.enable
191+ description = "mwlib job queue server";
193+ wantedBy = [ "multi-user.target" ];
194+ after = [ "network.target" "local-fs.target" ];
197+ mkdir -pv '${cfg.qserve.datadir}'
198+ chown -Rc ${cfg.qserve.user}:`id -ng ${cfg.qserve.user}` '${cfg.qserve.datadir}'
199+ chmod -Rc u=rwX,go= '${cfg.qserve.datadir}'
203+ ExecStart = concatStringsSep " " (
205+ "${mwlib}/bin/mw-qserve"
206+ "-p ${toString cfg.qserve.port}"
207+ "-i ${cfg.qserve.address}"
208+ "-d ${cfg.qserve.datadir}"
209+ ] ++ map (a: "-a ${a}") cfg.qserve.allow
211+ User = cfg.qserve.user;
212+ PermissionsStartOnly = true;
214+ }; # systemd.services.mwlib-qserve
216+ systemd.services.mwlib-nslave = mkIf cfg.nslave.enable
218+ description = "mwlib worker";
220+ wantedBy = [ "multi-user.target" ];
221+ after = [ "network.target" "local-fs.target" ];
224+ mkdir -pv '${cfg.nslave.cachedir}'
225+ chown -Rc ${cfg.nslave.user}:`id -ng ${cfg.nslave.user}` '${cfg.nslave.cachedir}'
226+ chmod -Rc u=rwX,go= '${cfg.nslave.cachedir}'
230+ PYTHONPATH = concatMapStringsSep ":"
231+ (m: "${pypkgs.${m}}/lib/${python.libPrefix}/site-packages")
232+ [ "mwlib-rl" "mwlib-ext" "pygments" ];
236+ ExecStart = concatStringsSep " " (
238+ "${mwlib}/bin/nslave"
239+ "--cachedir ${cfg.nslave.cachedir}"
240+ "--numprocs ${toString cfg.nslave.numprocs}"
241+ "--url ${cfg.nslave.http.url}"
243+ if cfg.nslave.http.enable then
245+ "--serve-files-port ${toString cfg.nslave.http.port}"
246+ "--serve-files-address ${cfg.nslave.http.address}"
252+ User = cfg.nslave.user;
253+ PermissionsStartOnly = true;
255+ }; # systemd.services.mwlib-nslave