0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-09 12:05:50 +03:00

nixos/services.rippleDataApi: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:46:44 +02:00
parent ba6e7e10bb
commit 0280cad999

View file

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