-
Notifications
You must be signed in to change notification settings - Fork 19
/
nixos-module.nix
133 lines (131 loc) · 4.15 KB
/
nixos-module.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
{config, pkgs, lib, ...}: let
cfg = config.services.blockfrost;
settingsFormat = pkgs.formats.json {};
in {
options = {
services.blockfrost = {
enable = lib.mkEnableOption "Blockfrost";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.blockfrost-backend-ryo;
};
stateDir = lib.mkOption {
type = lib.types.path;
default = "${cfg.baseWorkDir}blockfrost";
};
user = lib.mkOption {
description = "User to run blockfrost service as";
type = lib.types.str;
default = "blockfrost";
};
group = lib.mkOption {
description = "Group to run blockfrost service as";
type = lib.types.str;
default = "blockfrost";
};
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
server = {
listenAddress = lib.mkOption {
type = lib.types.str;
default = "localhost";
};
port = lib.mkOption {
type = lib.types.port;
default = 3000;
};
debug = lib.mkOption {
type = lib.types.bool;
default = false;
};
prometheusMetrics = lib.mkOption {
type = lib.types.bool;
default = false;
};
};
dbSync = {
host = lib.mkOption {
type = lib.types.str;
default = "localhost";
};
port = lib.mkOption {
type = lib.types.port;
default = 5432;
};
user = lib.mkOption {
type = lib.types.str;
default = "cexplorer";
};
database = lib.mkOption {
type = lib.types.str;
default = "cdbsync";
};
maxConnections = lib.mkOption {
type = lib.types.int;
default = 10;
};
};
network = lib.mkOption {
type = lib.types.enum [ "mainnet" "preprod" "preview" "testnet" "sanchonet" ];
default = "mainnet";
};
tokenRegistryUrl = lib.mkOption {
type = lib.types.str;
default = "https://tokens.cardano.org";
};
};
};
default = {};
description = ''
Freeform attrset that generates the JSON configuration file used by Blockfrost.
'';
example = ''
{
user = config.services.cardano-db-sync.postgres.user;
port = config.services.cardano-db-sync.postgres.port;
database = config.services.cardano-db-sync.postgres.database;
host = config.services.cardano-db-sync.postgres.socketdir;
}
'';
};
baseWorkDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/";
internal = true;
};
requires = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "cardano-db-sync.service" ];
internal = true;
};
};
};
config = lib.mkIf cfg.enable {
users.users.blockfrost = lib.mkIf (cfg.user == "blockfrost") {
isSystemUser = true;
group = cfg.group;
home = cfg.stateDir;
};
users.groups.blockfrost = lib.mkIf (cfg.group == "blockfrost") { };
systemd.tmpfiles.rules = [
"d /var/lib/blockfrost-backend-ryo 770 ${cfg.user} ${cfg.group}"
];
systemd.services.blockfrost-backend-ryo = {
inherit (cfg) requires;
wantedBy = [ "multi-user.target" ];
environment = {
NODE_CONFIG_RUNTIME_JSON = settingsFormat.generate "blockfrost-settings.json" cfg.settings;
HOME = "/var/lib/blockfrost-backend-ryo";
};
serviceConfig = {
ExecStart = "${cfg.package}/bin/blockfrost-backend-ryo";
Group = cfg.group;
User = cfg.user;
StateDirectory = lib.removePrefix cfg.baseWorkDir cfg.stateDir;
WorkingDirectory = cfg.stateDir;
};
};
};
}