diff --git a/nixos/modules/services/misc/ripple-data-api.nix b/nixos/modules/services/misc/ripple-data-api.nix index a699ce95cf0e..e01e891c95a8 100644 --- a/nixos/modules/services/misc/ripple-data-api.nix +++ b/nixos/modules/services/misc/ripple-data-api.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.services.rippleDataApi; @@ -23,8 +20,8 @@ let db_config = builtins.toJSON { production = { - username = optional (cfg.couchdb.pass != "") cfg.couchdb.user; - password = optional (cfg.couchdb.pass != "") cfg.couchdb.pass; + username = lib.optional (cfg.couchdb.pass != "") cfg.couchdb.user; + password = lib.optional (cfg.couchdb.pass != "") cfg.couchdb.pass; host = cfg.couchdb.host; port = cfg.couchdb.port; database = cfg.couchdb.db; @@ -35,105 +32,105 @@ let in { options = { services.rippleDataApi = { - enable = mkEnableOption "ripple data api"; + enable = lib.mkEnableOption "ripple data api"; - port = mkOption { + port = lib.mkOption { description = "Ripple data api port"; default = 5993; - type = types.port; + type = lib.types.port; }; - importMode = mkOption { + importMode = lib.mkOption { description = "Ripple data api import mode."; default = "liveOnly"; - type = types.enum ["live" "liveOnly"]; + type = lib.types.enum ["live" "liveOnly"]; }; - minLedger = mkOption { + minLedger = lib.mkOption { description = "Ripple data api minimal ledger to fetch."; default = null; - type = types.nullOr types.int; + type = lib.types.nullOr lib.types.int; }; - maxLedger = mkOption { + maxLedger = lib.mkOption { description = "Ripple data api maximal ledger to fetch."; default = null; - type = types.nullOr types.int; + type = lib.types.nullOr lib.types.int; }; redis = { - enable = mkOption { + enable = lib.mkOption { description = "Whether to enable caching of ripple data to redis."; default = true; - type = types.bool; + type = lib.types.bool; }; - host = mkOption { + host = lib.mkOption { description = "Ripple data api redis host."; default = "localhost"; - type = types.str; + type = lib.types.str; }; - port = mkOption { + port = lib.mkOption { description = "Ripple data api redis port."; default = 5984; - type = types.port; + type = lib.types.port; }; }; couchdb = { - host = mkOption { + host = lib.mkOption { description = "Ripple data api couchdb host."; default = "localhost"; - type = types.str; + type = lib.types.str; }; - port = mkOption { + port = lib.mkOption { description = "Ripple data api couchdb port."; default = 5984; - type = types.port; + type = lib.types.port; }; - db = mkOption { + db = lib.mkOption { description = "Ripple data api couchdb database."; default = "rippled"; - type = types.str; + type = lib.types.str; }; - user = mkOption { + user = lib.mkOption { description = "Ripple data api couchdb username."; default = "rippled"; - type = types.str; + type = lib.types.str; }; - pass = mkOption { + pass = lib.mkOption { description = "Ripple data api couchdb password."; default = ""; - type = types.str; + type = lib.types.str; }; - create = mkOption { + create = lib.mkOption { description = "Whether to create couchdb database needed by ripple data api."; - type = types.bool; + type = lib.types.bool; default = true; }; }; - rippleds = mkOption { + rippleds = lib.mkOption { description = "List of rippleds to be used by ripple data api."; default = [ "http://s_east.ripple.com:51234" "http://s_west.ripple.com:51234" ]; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; }; }; }; - config = mkIf (cfg.enable) { - services.couchdb.enable = mkDefault true; - services.couchdb.bindAddress = mkDefault "0.0.0.0"; - services.redis.enable = mkDefault true; + config = lib.mkIf (cfg.enable) { + services.couchdb.enable = lib.mkDefault true; + services.couchdb.bindAddress = lib.mkDefault "0.0.0.0"; + services.redis.enable = lib.mkDefault true; systemd.services.ripple-data-api = { after = [ "couchdb.service" "redis.service" "ripple-data-api-importer.service" ]; @@ -176,9 +173,9 @@ in { User = "ripple-data-api"; }; - preStart = mkMerge [ - (mkIf (cfg.couchdb.create) '' - HOST="http://${optionalString (cfg.couchdb.pass != "") "${cfg.couchdb.user}:${cfg.couchdb.pass}@"}${cfg.couchdb.host}:${toString cfg.couchdb.port}" + preStart = lib.mkMerge [ + (lib.mkIf (cfg.couchdb.create) '' + HOST="http://${lib.optionalString (cfg.couchdb.pass != "") "${cfg.couchdb.user}:${cfg.couchdb.pass}@"}${cfg.couchdb.host}:${toString cfg.couchdb.port}" curl -X PUT $HOST/${cfg.couchdb.db} || true '') "${pkgs.ripple-data-api}/bin/update-views"