-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexstody-btc.nix
135 lines (133 loc) · 4.07 KB
/
hexstody-btc.nix
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{ config, pkgs, lib, ... }:
with lib; # use the functions from lib, such as mkIf
let
# the values of the options set for the service by the user of the service
cfg = config.services.hexstody-btc;
in {
##### interface. here we define the options that users of our service can specify
options = {
# the options for our service will be located under services.hexstody-btc
services.hexstody-btc = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable hexstody BTC adapter service by default.
'';
};
package = mkOption {
type = types.package;
default = pkgs.hexstody;
description = ''
Which package to use with the service.
'';
};
port = mkOption {
type = types.int;
default = 8180;
description = ''
Which port the BTC adapter listen to serve API.
'';
};
host = mkOption {
type = types.str;
default = "0.0.0.0";
description = ''
Which hostname is binded to the node.
'';
};
domain = mkOption {
type = types.str;
description = ''
Which domain is binded to the node.
'';
};
operatorKeys = mkOption {
type = types.listOf types.str;
description = ''
Public keys of operators
'';
};
btcNode = mkOption {
type = types.str;
default = "127.0.0.1:8332/wallet/hexstody";
description = ''
Host and port where BTC RPC node is located.
'';
};
rpcUser = mkOption {
type = types.str;
default = "bitcoin";
description = ''
Which name of bitcoin RPC user to use.
'';
};
passwordFile = mkOption {
type = types.str;
default = "/run/keys/hexstodybtcrpc";
description = ''
Location of file with password for RPC.
'';
};
passwordFileService = mkOption {
type = types.str;
default = "hexstodybtcrpc-key.service";
description = ''
Service that indicates that passwordFile is ready.
'';
};
secretKey = mkOption {
type = types.str;
default = "/run/keys/hexstodybtccookieskey";
description = ''
Location of file with cookies secret key.
'';
};
secretKeyService = mkOption {
type = types.str;
default = "hexstodybtccookies-key.service";
description = ''
Service that indicates that secretKey is ready.
'';
};
};
};
##### implementation
config = mkIf cfg.enable { # only apply the following settings if enabled
# User to run the node
users.users.hexstody-btc = {
name = "hexstody-btc";
group = "hexstody-btc";
description = "hexstody-btc daemon user";
isSystemUser = true;
};
users.groups.hexstody-btc = {};
# Create systemd service
systemd.services.hexstody-btc = {
enable = true;
description = "Hexstody BTC adapter";
after = ["network.target" cfg.passwordFileService cfg.secretKeyService];
wants = ["network.target" cfg.passwordFileService cfg.secretKeyService];
script = let
mkKeyFile = content: pkgs.writeText "operator-pubkey.pem" content;
in ''
export HEXSTODY_BTC_NODE_PASSWORD=$(cat ${cfg.passwordFile} | xargs echo -n)
export HEXSTODY_BTC_SECRET_KEY=$(cat ${cfg.secretKey} | xargs echo -n)
${cfg.package}/bin/hexstody-btc serve \
--address ${cfg.host} \
--node-url ${cfg.btcNode} \
--node-user ${cfg.rpcUser} \
--port ${builtins.toString cfg.port} \
--hot-domain ${cfg.domain} \
--operator-public-keys ${pkgs.lib.concatStringsSep " " (builtins.map mkKeyFile cfg.operatorKeys)}
'';
serviceConfig = {
Restart = "always";
RestartSec = 30;
User = "hexstody-btc";
LimitNOFILE = 65536;
};
wantedBy = ["multi-user.target"];
};
};
}