1 { config, lib, pkgs, ... }:
6 cfg = config.services.rippleDataApi;
8 deployment_env_config = builtins.toJSON {
10 port = toString cfg.port;
14 rippleds = cfg.rippleds;
16 enable = cfg.redis.enable;
17 host = cfg.redis.host;
18 port = cfg.redis.port;
19 options.auth_pass = null;
24 db_config = builtins.toJSON {
26 username = optional (cfg.couchdb.pass != "") cfg.couchdb.user;
27 password = optional (cfg.couchdb.pass != "") cfg.couchdb.pass;
28 host = cfg.couchdb.host;
29 port = cfg.couchdb.port;
30 database = cfg.couchdb.db;
37 services.rippleDataApi = {
38 enable = mkEnableOption "ripple data api";
41 description = "Ripple data api port";
46 importMode = mkOption {
47 description = "Ripple data api import mode.";
49 type = types.enum ["live" "liveOnly"];
52 minLedger = mkOption {
53 description = "Ripple data api minimal ledger to fetch.";
55 type = types.nullOr types.int;
58 maxLedger = mkOption {
59 description = "Ripple data api maximal ledger to fetch.";
61 type = types.nullOr types.int;
66 description = "Whether to enable caching of ripple data to redis.";
72 description = "Ripple data api redis host.";
73 default = "localhost";
78 description = "Ripple data api redis port.";
86 description = "Ripple data api couchdb host.";
87 default = "localhost";
92 description = "Ripple data api couchdb port.";
98 description = "Ripple data api couchdb database.";
104 description = "Ripple data api couchdb username.";
110 description = "Ripple data api couchdb password.";
116 description = "Whether to create couchdb database needed by ripple data api.";
122 rippleds = mkOption {
123 description = "List of rippleds to be used by ripple data api.";
125 "http://s_east.ripple.com:51234"
126 "http://s_west.ripple.com:51234"
128 type = types.listOf types.str;
133 config = mkIf (cfg.enable) {
134 services.couchdb.enable = mkDefault true;
135 services.couchdb.bindAddress = mkDefault "0.0.0.0";
136 services.redis.enable = mkDefault true;
138 systemd.services.ripple-data-api = {
139 after = [ "couchdb.service" "redis.service" "ripple-data-api-importer.service" ];
140 wantedBy = [ "multi-user.target" ];
143 NODE_ENV = "production";
144 DEPLOYMENT_ENVS_CONFIG = pkgs.writeText "deployment.environment.json" deployment_env_config;
145 DB_CONFIG = pkgs.writeText "db.config.json" db_config;
149 ExecStart = "${pkgs.ripple-data-api}/bin/api";
151 User = "ripple-data-api";
155 systemd.services.ripple-data-importer = {
156 after = [ "couchdb.service" ];
157 wantedBy = [ "multi-user.target" ];
158 path = [ pkgs.curl ];
161 NODE_ENV = "production";
162 DEPLOYMENT_ENVS_CONFIG = pkgs.writeText "deployment.environment.json" deployment_env_config;
163 DB_CONFIG = pkgs.writeText "db.config.json" db_config;
164 LOG_FILE = "/dev/null";
169 if cfg.minLedger != null && cfg.maxLedger != null then
170 "${toString cfg.minLedger} ${toString cfg.maxLedger}"
174 ExecStart = "${pkgs.ripple-data-api}/bin/importer ${importMode} debug";
176 User = "ripple-data-api";
180 (mkIf (cfg.couchdb.create) ''
181 HOST="http://${optionalString (cfg.couchdb.pass != "") "${cfg.couchdb.user}:${cfg.couchdb.pass}@"}${cfg.couchdb.host}:${toString cfg.couchdb.port}"
182 curl -X PUT $HOST/${cfg.couchdb.db} || true
184 "${pkgs.ripple-data-api}/bin/update-views"
188 users.users.ripple-data-api =
189 { description = "Ripple data api user";
191 group = "ripple-data-api";
193 users.groups.ripple-data-api = {};