~sumner/nixos-configuration

ref: f4eb6417bc48729411263dc754fbe8c63a65d5bf nixos-configuration/modules/services/matrix/quotesfilebot.nix -rw-r--r-- 1.9 KiB
f4eb6417Sumner Evans standupbot: 0.4.1rc2 0.4.1rc3 8 months ago
                                                                                
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
{ config, lib, pkgs, ... }: with lib; let
  cfg = config.services.quotesfilebot;
  quotesfilebot = pkgs.callPackage ../../../pkgs/quotesfilebot {};

  quotesfilebotConfig = {
    DefaultReactionEmoji = cfg.defaultReactionEmoji;
    Username = cfg.username;
    Homeserver = cfg.homeserver;
    PasswordFile = cfg.passwordFile;
    JoinMessage = cfg.joinMessage;
  };
  format = pkgs.formats.json {};
  quotesfilebotConfigJson = format.generate "quotesfilebot.json" quotesfilebotConfig;
in
{
  options = {
    services.quotesfilebot = {
      enable = mkEnableOption "quotesfilebot";
      defaultReactionEmoji = mkOption {
        type = types.str;
        default = "💬";
      };
      username = mkOption {
        type = types.str;
        default = "@quotesfilebot:${config.networking.domain}";
      };
      homeserver = mkOption {
        type = types.str;
        default = "http://localhost:8008";
      };
      passwordFile = mkOption {
        type = types.path;
        default = "/var/lib/quotesfilebot/passwordfile";
      };
      dataDir = mkOption {
        type = types.path;
        default = "/var/lib/quotesfilebot";
      };
      joinMessage = mkOption {
        type = types.str;
        default = "I'm a quotesfilebot!";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.quotesfilebot = {
      description = "Quotesfilebot";
      after = [ "matrix-synapse.service" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStart = ''
          ${quotesfilebot}/bin/quotes-file-bot --config ${quotesfilebotConfigJson}
        '';
        Restart = "on-failure";
        User = "quotesfilebot";
      };
    };

    users = {
      users.quotesfilebot = {
        group = "quotesfilebot";
        isSystemUser = true;
        home = cfg.dataDir;
        createHome = true;
      };
      groups.quotesfilebot = {};
    };
  };
}