2024-07-03 15:46:20 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
self,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
name = "matrix-bot";
|
|
|
|
in
|
|
|
|
{
|
2024-07-03 17:35:02 +00:00
|
|
|
users.groups.matrix-bot-user = { };
|
|
|
|
users.users.matrix-bot-user = {
|
|
|
|
group = "matrix-bot-user";
|
|
|
|
isSystemUser = true;
|
|
|
|
description = "User for matrix-bot service";
|
|
|
|
home = "/var/lib/matrix-bot";
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
2024-07-03 15:46:20 +00:00
|
|
|
systemd.services.${name} = {
|
|
|
|
path = [ self.packages.${pkgs.system}.matrix-bot ];
|
|
|
|
description = "Matrix bot for changelog and reviews";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
2024-07-03 16:05:51 +00:00
|
|
|
MATRIX_PASSWORD_FILE = "%d/MATRIX_PASSWORD_FILE";
|
|
|
|
OPENAI_API_KEY_FILE = "%d/OPENAI_API_KEY_FILE";
|
2024-07-03 17:35:02 +00:00
|
|
|
HOME = "/var/lib/${name}";
|
2024-07-03 15:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
LoadCredential = [
|
2024-07-03 16:05:51 +00:00
|
|
|
"MATRIX_PASSWORD_FILE:${config.sops.secrets.web01-matrix-password-clan-bot.path}"
|
|
|
|
"OPENAI_API_KEY_FILE:${config.sops.secrets.qubasas-openai-api-key.path}"
|
2024-07-03 15:46:20 +00:00
|
|
|
];
|
2024-07-03 17:35:02 +00:00
|
|
|
User = "matrix-bot-user";
|
|
|
|
Group = "matrix-bot-user";
|
|
|
|
WorkingDirectory = "/var/lib/${name}";
|
|
|
|
RuntimeDirectory = "/var/lib/${name}";
|
2024-07-03 15:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
set -euxo pipefail
|
|
|
|
|
2024-07-03 17:08:08 +00:00
|
|
|
mbot --changelog-room "!FdCwyKsRlfooNYKYzx:matrix.org" --review-room "!tmSRJlbsVXFUKAddiM:gchq.icu"
|
2024-07-03 15:46:20 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|