forked from cardano-foundation/cardano-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cardano-graphql-service.nix
141 lines (125 loc) · 4.49 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
{ lib, pkgs, config, ... }:
let
cfg = config.services.cardano-graphql;
in {
options = {
services.cardano-graphql = {
enable = lib.mkEnableOption "cardano-explorer graphql service";
frontendPkg = lib.mkOption {
type = lib.types.package;
default = (import ../pkgs.nix {}).packages.cardano-graphql;
};
persistPkg = lib.mkOption {
type = lib.types.package;
default = (import ../pkgs.nix {}).packages.persistgraphql;
};
enginePort = lib.mkOption {
type = lib.types.int;
default = 9999;
};
listenAddress = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
loggerMinSeverity = lib.mkOption {
type = lib.types.str;
default = "info";
};
port = lib.mkOption {
type = lib.types.int;
default = 3100;
};
cardanoNodeConfigPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
hasuraIp = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
};
hasuraProtocol = lib.mkOption {
type = lib.types.str;
default = "http";
};
ogmiosHost = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
};
ogmiosPort = lib.mkOption {
type = lib.types.int;
default = 1337;
};
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";
};
pollingIntervalAdaSupply = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
maxQueryComplexity = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
};
};
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 = cfg.frontendPkg;
persistgraphql = cfg.persistPkg;
hasuraBaseUri = "${cfg.hasuraProtocol}://${cfg.hasuraIp}:${toString cfg.enginePort}";
pluginLibPath = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
];
in lib.mkIf cfg.enable {
systemd.services.cardano-graphql = {
wantedBy = [ "multi-user.target" ];
wants = [ "graphql-engine.service" ];
after = [ "graphql-engine.service" ];
environment = lib.filterAttrs (k: v: v != null) {
CARDANO_NODE_CONFIG_PATH = cfg.cardanoNodeConfigPath;
HASURA_GRAPHQL_ENABLE_TELEMETRY = toString false;
HASURA_URI = hasuraBaseUri;
LOGGER_MIN_SEVERITY = cfg.loggerMinSeverity;
OGMIOS_HOST = cfg.ogmiosHost;
OGMIOS_PORT = toString cfg.ogmiosPort;
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.listenAddress != null) { LISTEN_ADDRESS = cfg.listenAddress; }) //
(lib.optionalAttrs (cfg.pollingIntervalAdaSupply != null) { POLLING_INTERVAL_ADA_SUPPLY = toString cfg.pollingIntervalAdaSupply; }) //
(lib.optionalAttrs (cfg.queryDepthLimit != null) { QUERY_DEPTH_LIMIT = toString cfg.queryDepthLimit; }) //
(lib.optionalAttrs (cfg.allowListPath != null) { ALLOW_LIST_PATH = cfg.allowListPath; }) //
(lib.optionalAttrs (cfg.maxQueryComplexity != null) { MAX_QUERY_COMPLEXITY = toString cfg.maxQueryComplexity; });
path = with pkgs; [ netcat curl frontend glibc.bin patchelf ];
script = ''
exec cardano-graphql
'';
};
};
}