base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / nixos / modules / services / matrix / hebbot.nix
blobba676422ca1fdaf42547b1593918d2029c981262
1 { lib
2 , config
3 , pkgs
4 , ...
5 }:
7 let
8   inherit (lib) mkEnableOption mkOption mkIf types;
9   format = pkgs.formats.toml { };
10   cfg = config.services.hebbot;
11   settingsFile = format.generate "config.toml" cfg.settings;
12   mkTemplateOption = templateName: mkOption {
13     type = types.path;
14     description = ''
15       A path to the Markdown file for the ${templateName}.
16     '';
17   };
19   {
20     meta.maintainers = [ lib.maintainers.raitobezarius ];
21     options.services.hebbot = {
22       enable = mkEnableOption "hebbot";
23       botPasswordFile = mkOption {
24         type = types.path;
25         description = ''
26           A path to the password file for your bot.
28           Consider using a path that does not end up in your Nix store
29           as it would be world readable.
30         '';
31       };
32       templates = {
33         project = mkTemplateOption "project template";
34         report = mkTemplateOption "report template";
35         section = mkTemplateOption "section template";
36       };
37       settings = mkOption {
38         type = format.type;
39         default = { };
40         description = ''
41           Configuration for Hebbot, see, for examples:
43           - <https://github.com/matrix-org/twim-config/blob/master/config.toml>
44           - <https://gitlab.gnome.org/Teams/Websites/thisweek.gnome.org/-/blob/main/hebbot/config.toml>
45         '';
46       };
47     };
49     config = mkIf cfg.enable {
50       systemd.services.hebbot = {
51         description = "hebbot - a TWIM-style Matrix bot written in Rust";
52         after = [ "network.target" ];
53         wantedBy = [ "multi-user.target" ];
55         preStart = ''
56           ln -sf ${cfg.templates.project} ./project_template.md
57           ln -sf ${cfg.templates.report} ./report_template.md
58           ln -sf ${cfg.templates.section} ./section_template.md
59           ln -sf ${settingsFile} ./config.toml
60         '';
62         script = ''
63           export BOT_PASSWORD="$(cat $CREDENTIALS_DIRECTORY/bot-password-file)"
64           ${lib.getExe pkgs.hebbot}
65         '';
67         serviceConfig = {
68           DynamicUser = true;
69           Restart = "on-failure";
70           LoadCredential = "bot-password-file:${cfg.botPasswordFile}";
71           RestartSec = "10s";
72           StateDirectory = "hebbot";
73           WorkingDirectory = "/var/lib/hebbot";
74       };
75     };
76   };