summary refs log tree commit diff
path: root/nixos/modules/services/misc/ripple-rest.nix
blob: 49520f68a50a704c59e1e61feb7495c157d8ab19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.rippleRest;

  configFile = pkgs.writeText "ripple-rest-config.json" (builtins.toJSON {
    config_version = "2.0.3";
    debug = cfg.debug;
    port = cfg.port;
    host = cfg.host;
    ssl_enabled = cfg.ssl.enable;
    ssl = {
      key_path = cfg.ssl.keyPath;
      cert_path = cfg.ssl.certPath;
      reject_unathorized = cfg.ssl.rejectUnathorized;
    };
    db_path = cfg.dbPath;
    max_transaction_fee = cfg.maxTransactionFee;
    rippled_servers = cfg.rippleds;
  });

in {
  options.services.rippleRest = {
    enable = mkEnableOption "ripple rest";

    debug = mkEnableOption "debug for ripple-rest";

    host = mkOption {
      description = "Ripple rest host.";
      default = "localhost";
      type = types.str;
    };

    port = mkOption {
      description = "Ripple rest port.";
      default = 5990;
      type = types.int;
    };

    ssl = {
      enable = mkEnableOption "ssl";

      keyPath = mkOption {
        description = "Path to the ripple rest key file.";
        default = null;
        type = types.nullOr types.path;
      };


      certPath = mkOption {
        description = "Path to the ripple rest cert file.";
        default = null;
        type = types.nullOr types.path;
      };

      rejectUnathorized = mkOption {
        description = "Whether to reject unatohroized.";
        default = true;
        type = types.bool;
      };
    };

    dbPath = mkOption {
      description = "Ripple rest database path.";
      default = "${cfg.dataDir}/ripple-rest.db";
      type = types.path;
    };

    maxTransactionFee = mkOption {
      description = "Ripple rest max transaction fee.";
      default = 1000000;
      type = types.int;
    };

    rippleds = mkOption {
      description = "List of rippled servers.";
      default = [
        "wss://s1.ripple.com:443"
      ];
      type = types.listOf types.str;
    };

    dataDir = mkOption {
      description = "Ripple rest data directory.";
      default = "/var/lib/ripple-rest";
      type = types.path;
    };
  };

  config = mkIf (cfg.enable) {
    systemd.services.ripple-rest = {
      wantedBy = [ "multi-user.target"];
      after = ["network.target" ];
      environment.NODE_PATH="${pkgs.ripple-rest}/lib/node_modules/ripple-rest/node_modules";
      serviceConfig = {
        ExecStart = "${pkgs.nodejs}/bin/node ${pkgs.ripple-rest}/lib/node_modules/ripple-rest/server/server.js --config ${configFile}";
        User = "ripple-rest";
      };
    };

    users.extraUsers.postgres = {
      name = "ripple-rest";
      uid = config.ids.uids.ripple-rest;
      createHome = true;
      home = cfg.dataDir;
    };
  };
}