forked from cardano-foundation/cardano-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cardano-graphql-service.nix
140 lines (124 loc) · 4.33 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
# WARNING!!! THIS IS BROKEN! DO NOT USE!
{ lib, pkgs, config, ... }:
let
cfg = config.services.cardano-graphql;
sources = import ../sources.nix;
in {
options = {
services.cardano-graphql = {
enable = lib.mkEnableOption "cardano-explorer graphql service";
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";
};
whitelistPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Source directory or file to generate whitelist 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 = (import ../../.).cardano-graphql;
persistgraphql = (import ../../.).persistgraphql;
hasura-cli = (import ../../.).hasura-cli;
hasura-cli-ext = (import ../../.).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_URI = hasuraBaseUri;
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.whitelistPath != null) { WHITELIST_PATH = cfg.whitelistPath; });
path = with pkgs; [ netcat curl postgresql jq frontend hasura-cli glibc.bin patchelf ];
preStart = ''
set -exuo pipefail
${installHasuraCLI}
'';
script = ''
exec cardano-graphql
'';
};
};
}