-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
100 lines (95 loc) · 2.38 KB
/
module.nix
File metadata and controls
100 lines (95 loc) · 2.38 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
{ pkgs, config, lib, ... }:
let
cfg = config.TLMS.bureaucrat;
in
{
options.TLMS.bureaucrat = with lib; {
enable = mkOption {
type = types.bool;
default = false;
description = ''Wether to enable bureaucrat service'';
};
grpc = {
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
To which IP bureaucrat should bind its grpc server.
'';
};
port = mkOption {
type = types.port;
default = 8080;
description = ''
To which port should bureaucrat bind its grpc server.
'';
};
};
redis = {
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 = "bureaucrat";
description = ''systemd user'';
};
group = mkOption {
type = types.str;
default = "bureaucrat";
description = ''group of systemd user'';
};
log_level = mkOption {
type = types.str;
default = "info";
description = ''log level of the application'';
};
};
config = lib.mkIf cfg.enable {
systemd = {
services = {
"bureaucrat" = {
enable = true;
wantedBy = [ "multi-user.target" "redis.service"];
script = ''
exec ${pkgs.bureaucrat}/bin/bureaucrat&
'';
environment = {
"RUST_LOG" = "${cfg.log_level}";
"RUST_BACKTRACE" = if (cfg.log_level == "info") then "0" else "1";
"BUREAUCRAT_HOST" = "${cfg.grpc.host}:${toString cfg.grpc.port}";
"REDIS_HOST" = "${cfg.redis.host}";
"REDIS_PORT" = "${toString cfg.redis.port}";
};
serviceConfig = {
Type = "forking";
User = cfg.user;
Restart = "always";
};
};
};
};
# user accounts for systemd units
users.users."${cfg.user}" = {
name = "${cfg.user}";
description = "This guy runs bureaucrat";
isNormalUser = false;
isSystemUser = true;
group = cfg.group;
extraGroups = [ ];
};
users.groups."${cfg.group}" = {};
};
}