at 17.09-beta 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.parsoid; 8 9 confTree = { 10 worker_heartbeat_timeout = 300000; 11 logging = { level = "info"; }; 12 services = [{ 13 module = "lib/index.js"; 14 entrypoint = "apiServiceWorker"; 15 conf = { 16 mwApis = map (x: if isAttrs x then x else { uri = x; }) cfg.wikis; 17 serverInterface = cfg.interface; 18 serverPort = cfg.port; 19 }; 20 }]; 21 }; 22 23 confFile = pkgs.writeText "config.yml" (builtins.toJSON (recursiveUpdate confTree cfg.extraConfig)); 24 25in 26{ 27 ##### interface 28 29 options = { 30 31 services.parsoid = { 32 33 enable = mkOption { 34 type = types.bool; 35 default = false; 36 description = '' 37 Whether to enable Parsoid -- bidirectional 38 wikitext parser. 39 ''; 40 }; 41 42 wikis = mkOption { 43 type = types.listOf (types.either types.str types.attrs); 44 example = [ "http://localhost/api.php" ]; 45 description = '' 46 Used MediaWiki API endpoints. 47 ''; 48 }; 49 50 workers = mkOption { 51 type = types.int; 52 default = 2; 53 description = '' 54 Number of Parsoid workers. 55 ''; 56 }; 57 58 interface = mkOption { 59 type = types.str; 60 default = "127.0.0.1"; 61 description = '' 62 Interface to listen on. 63 ''; 64 }; 65 66 port = mkOption { 67 type = types.int; 68 default = 8000; 69 description = '' 70 Port to listen on. 71 ''; 72 }; 73 74 extraConfig = mkOption { 75 type = types.attrs; 76 default = {}; 77 description = '' 78 Extra configuration to add to parsoid configuration. 79 ''; 80 }; 81 82 }; 83 84 }; 85 86 ##### implementation 87 88 config = mkIf cfg.enable { 89 90 systemd.services.parsoid = { 91 description = "Bidirectional wikitext parser"; 92 wantedBy = [ "multi-user.target" ]; 93 after = [ "network.target" ]; 94 serviceConfig = { 95 User = "nobody"; 96 ExecStart = "${pkgs.nodePackages.parsoid}/lib/node_modules/parsoid/bin/server.js -c ${confFile} -n ${toString cfg.workers}"; 97 }; 98 }; 99 100 }; 101 102}