-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
235 lines (185 loc) · 7.16 KB
/
flake.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{
description = "valorant discord bot";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
valorant-utils = {
url = "github:make-or-break/valorant-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
valorant-match-history = {
url = "github:make-or-break/valorant-match-history";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.valorant-utils.follows = "valorant-utils";
};
};
outputs = { self, nixpkgs, flake-utils, ... }:
{
nixosModules.default = self.nixosModules.valorant-discord-bot;
nixosModules.valorant-discord-bot = { lib, pkgs, config, ... }:
with lib;
let cfg = config.services.valorant-discord-bot;
in
{
options.services.valorant-discord-bot = {
enable = mkEnableOption "valorant-discord-bot";
dataDir = mkOption {
type = types.str;
default = "/var/lib/valorant";
description = ''
The directory where valorant discord bot stores it's data files. If left as the default value this directory will automatically be created before the server starts, otherwise the sysadmin is responsible for ensuring the directory exists with appropriate ownership and permissions.
'';
};
envfile = mkOption {
type = types.str;
default = "/var/src/secrets/valorant/envfile";
description = ''
The location of the envfile containing secrets
'';
};
user = mkOption {
type = types.str;
default = "valorant";
description = "User account under which valorant services run.";
};
group = mkOption {
type = types.str;
default = "valorant";
description = "Group under which which valorant services run.";
};
};
config = mkIf cfg.enable {
systemd.services.valorant-discord-bot = {
description = "A discord bot for our valorant group";
wantedBy = [ "multi-user.target" ];
serviceConfig = mkMerge [
{
EnvironmentFile = [ cfg.envfile ];
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;
ExecStart = "${self.packages."${pkgs.system}".valorant-discord-bot}/bin/valorant-discord-bot";
Restart = "on-failure";
}
(mkIf (cfg.dataDir == "/var/lib/valorant") {
StateDirectory = "valorant";
})
];
};
users.users = mkIf
(cfg.user == "valorant")
{
valorant = {
isSystemUser = true;
group = cfg.group;
description = "valorant system user";
};
};
users.groups =
mkIf
(cfg.group == "valorant")
{ valorant = { }; };
};
meta = { maintainers = with lib.maintainers; [ mayniklas ]; };
};
nixosModules.valorant-match-history = { lib, pkgs, config, ... }:
with lib;
let cfg = config.services.valorant-match-history;
in
{
options.services.valorant-match-history = {
enable = mkEnableOption "valorant match history";
dataDir = mkOption {
type = types.str;
default = "/var/lib/valorant";
description = ''
The directory where valorant-match-history stores it's data files. If left as the default value this directory will automatically be created before the server starts, otherwise the sysadmin is responsible for ensuring the directory exists with appropriate ownership and permissions.
'';
};
user = mkOption {
type = types.str;
default = "valorant";
description = "User account under which valorant services run.";
};
group = mkOption {
type = types.str;
default = "valorant";
description = "Group under which which valorant services run.";
};
};
config = mkIf cfg.enable {
systemd.timers.valorant-match-history = {
wantedBy = [ "timers.target" ];
partOf = [ "valorant-match-history.service" ];
timerConfig.OnCalendar = "*:0/15";
};
systemd.services.valorant-match-history = {
serviceConfig = mkMerge [
{
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;
Type = "oneshot";
ExecStart = "${self.inputs.valorant-match-history.packages."${pkgs.system}".valorant-match-history}/bin/valorant-match-history";
}
(mkIf (cfg.dataDir == "/var/lib/valorant") {
StateDirectory = "valorant";
})
];
};
users.users = mkIf
(cfg.user == "valorant")
{
valorant = {
isSystemUser = true;
group = cfg.group;
description = "valorant system user";
};
};
users.groups =
mkIf
(cfg.group == "valorant")
{ valorant = { }; };
};
meta = { maintainers = with lib.maintainers; [ mayniklas ]; };
};
}
//
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
rec {
# Use nixpkgs-fmt for `nix fmt'
formatter = pkgs.nixpkgs-fmt;
defaultPackage = packages.valorant-discord-bot;
packages = flake-utils.lib.flattenTree rec {
valorant-discord-bot = with pkgs.python310Packages;
buildPythonPackage rec {
pname = "valorant-discord-bot";
version = "0.2.0";
src = self;
propagatedBuildInputs = [
# flake inputs
self.inputs.valorant-utils.packages.${system}.valorant-utils
self.inputs.valorant-match-history.packages.${system}.valorant-match-history
(discordpy.override { withVoice = false; })
sqlalchemy
];
doCheck = false;
pythonImportsCheck = [
"database.sql_scheme"
"database.sql_statements"
];
meta = with pkgs.lib; {
description = "valorant discord bot";
homepage = "https://github.com/make-or-break/valorant-discord-bot/";
platforms = platforms.unix;
maintainers = with maintainers; [ mayniklas ];
};
};
};
});
}