-
Notifications
You must be signed in to change notification settings - Fork 103
/
cardano-graphql-service.nix
160 lines (142 loc) · 4.87 KB
/
cardano-graphql-service.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# WARNING!!! THIS IS BROKEN! DO NOT USE!
{ lib, pkgs, config, ... }:
let
cfg = config.services.cardano-graphql;
selfPkgs = import ../pkgs.nix {};
in {
options = {
services.cardano-graphql = {
enable = lib.mkEnableOption "cardano-explorer graphql service";
dbHost = lib.mkOption {
type = lib.types.str;
default = "/run/postgresql";
};
dbPassword = lib.mkOption {
type = lib.types.str;
default = ''""'';
};
dbPort = lib.mkOption {
type = lib.types.int;
default = 5432;
};
dbUser = lib.mkOption {
type = lib.types.str;
default = "cexplorer";
};
db = lib.mkOption {
type = lib.types.str;
default = "cexplorer";
};
enginePort = lib.mkOption {
type = lib.types.int;
default = 9999;
};
port = lib.mkOption {
type = lib.types.int;
default = 3100;
};
# Used if you tx submission is allowed
cardanoNodeSocketPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
genesisByron = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
genesisShelley = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
smashUrl = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
hasuraIp = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
};
hasuraProtocol = lib.mkOption {
type = lib.types.str;
default = "http";
};
enablePrometheus = lib.mkOption {
type = lib.types.bool;
default = true;
};
enableTracing = lib.mkEnableOption "tracing";
enableCache = lib.mkEnableOption "cache";
queryDepthLimit = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
allowedOrigins = lib.mkOption {
type = lib.types.nullOr (lib.types.separatedString " ");
default = null;
};
allowIntrospection = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Allows introspection queries";
};
allowListPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Source directory or file to generate allow-list from";
};
};
};
config = let
# TODO: there has to be a better way to handle boolean env vars in nodejs???
boolToNodeJSEnv = bool: if bool then "true" else "false";
frontend = selfPkgs.packages.cardano-graphql;
persistgraphql = selfPkgs.packages.persistgraphql;
hasura-cli = selfPkgs.packages.hasura-cli;
hasura-cli-ext = selfPkgs.packages.hasura-cli-ext;
hasuraBaseUri = "${cfg.hasuraProtocol}://${cfg.hasuraIp}:${toString cfg.enginePort}";
pluginLibPath = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
];
installHasuraCLI = ''
# always start with no plugins so future upgrades will work
rm -rf ~/.hasura/plugins
# TODO: identify how to get what's needed without the install of the broken plugin
hasura plugin install cli-ext
cp ${hasura-cli-ext}/bin/cli-ext-hasura-linux ~/.hasura/plugins/bin/hasura-cli_ext
'';
in lib.mkIf cfg.enable {
systemd.services.cardano-graphql = {
wantedBy = [ "multi-user.target" ];
requires = [ "graphql-engine.service" ];
environment = lib.filterAttrs (k: v: v != null) {
CARDANO_NODE_SOCKET_PATH = cfg.cardanoNodeSocketPath;
POOL_METADATA_PROXY = cfg.smashUrl;
GENESIS_FILE_BYRON = cfg.genesisByron;
GENESIS_FILE_SHELLEY = cfg.genesisShelley;
HASURA_CLI_PATH = hasura-cli + "/bin/hasura";
HASURA_URI = hasuraBaseUri;
POSTGRES_DB = cfg.db;
POSTGRES_HOST = cfg.dbHost;
POSTGRES_PASSWORD = cfg.dbPassword;
POSTGRES_PORT = toString cfg.dbPort;
POSTGRES_USER = cfg.dbUser;
PROMETHEUS_METRICS = boolToNodeJSEnv cfg.enablePrometheus;
TRACING = boolToNodeJSEnv (cfg.enableTracing || cfg.enablePrometheus);
ALLOW_INTROSPECTION = boolToNodeJSEnv cfg.allowIntrospection;
CACHE_ENABLED = boolToNodeJSEnv cfg.enableCache;
API_PORT = toString cfg.port;
} //
(lib.optionalAttrs (cfg.allowedOrigins != null) { ALLOWED_ORIGINS = cfg.allowedOrigins; }) //
(lib.optionalAttrs (cfg.queryDepthLimit != null) { QUERY_DEPTH_LIMIT = toString cfg.queryDepthLimit; }) //
(lib.optionalAttrs (cfg.allowListPath != null) { ALLOW_LIST_PATH = cfg.allowListPath; });
path = with pkgs; [ netcat curl postgresql jq frontend hasura-cli glibc.bin patchelf ];
preStart = ''
set -exuo pipefail
${installHasuraCLI}
'';
script = ''
exec cardano-graphql
'';
};
};
}