1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.parsoid; 8 9 conf = '' 10 exports.setup = function( parsoidConfig ) { 11 ${toString (mapAttrsToList (name: str: "parsoidConfig.setInterwiki('${name}', '${str}');") cfg.interwikis)} 12 13 parsoidConfig.serverInterface = "${cfg.interface}"; 14 parsoidConfig.serverPort = ${toString cfg.port}; 15 16 parsoidConfig.useSelser = true; 17 18 ${cfg.extraConfig} 19 }; 20 ''; 21 22 confFile = builtins.toFile "localsettings.js" conf; 23 24in 25{ 26 ##### interface 27 28 options = { 29 30 services.parsoid = { 31 32 enable = mkOption { 33 type = types.bool; 34 default = false; 35 description = '' 36 Whether to enable Parsoid -- bidirectional 37 wikitext parser. 38 ''; 39 }; 40 41 interwikis = mkOption { 42 type = types.attrsOf types.str; 43 example = { localhost = "http://localhost/api.php"; }; 44 description = '' 45 Used MediaWiki API endpoints. 46 ''; 47 }; 48 49 workers = mkOption { 50 type = types.int; 51 default = 2; 52 description = '' 53 Number of Parsoid workers. 54 ''; 55 }; 56 57 interface = mkOption { 58 type = types.str; 59 default = "127.0.0.1"; 60 description = '' 61 Interface to listen on. 62 ''; 63 }; 64 65 port = mkOption { 66 type = types.int; 67 default = 8000; 68 description = '' 69 Port to listen on. 70 ''; 71 }; 72 73 extraConfig = mkOption { 74 type = types.lines; 75 default = ""; 76 description = '' 77 Extra configuration to add to parsoid configuration. 78 ''; 79 }; 80 81 }; 82 83 }; 84 85 ##### implementation 86 87 config = mkIf cfg.enable { 88 89 systemd.services.parsoid = { 90 description = "Bidirectional wikitext parser"; 91 wantedBy = [ "multi-user.target" ]; 92 after = [ "network.target" ]; 93 serviceConfig = { 94 ExecStart = "${pkgs.nodePackages_0_10.parsoid}/lib/node_modules/parsoid/api/server.js -c ${confFile} -n ${toString cfg.workers}"; 95 }; 96 }; 97 98 }; 99 100}