-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule.nix
More file actions
159 lines (154 loc) · 4.11 KB
/
module.nix
File metadata and controls
159 lines (154 loc) · 4.11 KB
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
{ pkgs, config, lib, ... }:
let
cfg = config.TLMS.chemo;
in
{
options.TLMS.chemo = with lib; {
enable = mkOption {
type = types.bool;
default = false;
description = ''Wether to enable chemo service'';
};
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
To which IP chemo should bind its grpc server.
'';
};
port = mkOption {
type = types.port;
default = 8080;
description = ''
To which port should chemo bind its grpc_server.
'';
};
database = {
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
Database host
'';
};
port = mkOption {
type = types.port;
default = 5354;
description = ''
Database port
'';
};
user = mkOption {
type = types.str;
default = "chemo";
description = ''
user for postgres
'';
};
database = mkOption {
type = types.str;
default = "tlms";
description = ''
postgres database to use
'';
};
passwordFile = mkOption {
type = types.either types.path types.string;
default = "";
description = ''password file from which the postgres password can be read'';
};
};
user = mkOption {
type = types.str;
default = "chemo";
description = ''systemd user'';
};
group = mkOption {
type = types.str;
default = "chemo";
description = ''group of systemd user'';
};
log_level = mkOption {
type = types.str;
default = "info";
description = ''log level of the application'';
};
GRPC = mkOption {
type = types.listOf
(types.submodule {
options.schema = mkOption {
type = types.enum [ "http" "https" ];
default = "http";
description = ''
schema to connect to GRPC
'';
};
options.name = mkOption {
type = types.str;
default = "";
description = ''
GRPC name
'';
};
options.host = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
GRPC: schema://hostname
'';
};
options.port = mkOption {
type = types.port;
default = 50051;
description = ''
GRPC port
'';
};
});
default = [ ];
description = ''list of grpc endpoint where chemo should send data to'';
};
};
config = lib.mkIf cfg.enable {
systemd = {
services = {
"chemo" = {
enable = true;
wantedBy = [ "multi-user.target" ];
script = ''
exec ${pkgs.chemo}/bin/chemo&
'';
environment = {
"RUST_LOG" = "${cfg.log_level}";
"RUST_BACKTRACE" = if (cfg.log_level == "info") then "0" else "1";
"CHEMO_HOST" = "${cfg.host}:${toString cfg.port}";
"CHEMO_POSTGRES_PASSWORD_PATH" = "${cfg.database.passwordFile}";
"CHEMO_POSTGRES_HOST" = "${cfg.database.host}";
"CHEMO_POSTGRES_PORT" = "${toString cfg.database.port}";
"CHEMO_POSTGRES_USER" = "${toString cfg.database.user}";
"CHEMO_POSTGRES_DATABASE" = "${toString cfg.database.database}";
} // (lib.foldl
(x: y:
lib.mergeAttrs x { "CHEMO_GRPC_HOST_${y.name}" = "${y.schema}://${y.host}:${toString y.port}"; })
{ }
cfg.GRPC);
serviceConfig = {
Type = "forking";
User = cfg.user;
Restart = "always";
};
};
};
};
# user accounts for systemd units
users.users."${cfg.user}" = {
name = "${cfg.user}";
description = "This guy runs chemo";
isNormalUser = false;
isSystemUser = true;
group = cfg.group;
extraGroups = [ ];
};
users.groups."${cfg.group}" = {};
};
}