at 15.09-beta 2.7 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.rippleRest; 7 8 configFile = pkgs.writeText "ripple-rest-config.json" (builtins.toJSON { 9 config_version = "2.0.3"; 10 debug = cfg.debug; 11 port = cfg.port; 12 host = cfg.host; 13 ssl_enabled = cfg.ssl.enable; 14 ssl = { 15 key_path = cfg.ssl.keyPath; 16 cert_path = cfg.ssl.certPath; 17 reject_unathorized = cfg.ssl.rejectUnathorized; 18 }; 19 db_path = cfg.dbPath; 20 max_transaction_fee = cfg.maxTransactionFee; 21 rippled_servers = cfg.rippleds; 22 }); 23 24in { 25 options.services.rippleRest = { 26 enable = mkEnableOption "ripple rest"; 27 28 debug = mkEnableOption "debug for ripple-rest"; 29 30 host = mkOption { 31 description = "Ripple rest host."; 32 default = "localhost"; 33 type = types.str; 34 }; 35 36 port = mkOption { 37 description = "Ripple rest port."; 38 default = 5990; 39 type = types.int; 40 }; 41 42 ssl = { 43 enable = mkEnableOption "ssl"; 44 45 keyPath = mkOption { 46 description = "Path to the ripple rest key file."; 47 default = null; 48 type = types.nullOr types.path; 49 }; 50 51 52 certPath = mkOption { 53 description = "Path to the ripple rest cert file."; 54 default = null; 55 type = types.nullOr types.path; 56 }; 57 58 rejectUnathorized = mkOption { 59 description = "Whether to reject unatohroized."; 60 default = true; 61 type = types.bool; 62 }; 63 }; 64 65 dbPath = mkOption { 66 description = "Ripple rest database path."; 67 default = "${cfg.dataDir}/ripple-rest.db"; 68 type = types.path; 69 }; 70 71 maxTransactionFee = mkOption { 72 description = "Ripple rest max transaction fee."; 73 default = 1000000; 74 type = types.int; 75 }; 76 77 rippleds = mkOption { 78 description = "List of rippled servers."; 79 default = [ 80 "wss://s1.ripple.com:443" 81 ]; 82 type = types.listOf types.str; 83 }; 84 85 dataDir = mkOption { 86 description = "Ripple rest data directory."; 87 default = "/var/lib/ripple-rest"; 88 type = types.path; 89 }; 90 }; 91 92 config = mkIf (cfg.enable) { 93 systemd.services.ripple-rest = { 94 wantedBy = [ "multi-user.target"]; 95 after = ["network.target" ]; 96 environment.NODE_PATH="${pkgs.ripple-rest}/lib/node_modules/ripple-rest/node_modules"; 97 serviceConfig = { 98 ExecStart = "${pkgs.nodejs}/bin/node ${pkgs.ripple-rest}/lib/node_modules/ripple-rest/server/server.js --config ${configFile}"; 99 User = "ripple-rest"; 100 }; 101 }; 102 103 users.extraUsers.postgres = { 104 name = "ripple-rest"; 105 uid = config.ids.uids.ripple-rest; 106 createHome = true; 107 home = cfg.dataDir; 108 }; 109 }; 110}