about summary refs log tree commit diff
path: root/nix/modules/remarvin/default.nix
blob: d95e3f21326e3a9e93ccd2cabe534ba2e0c4c17e (plain)
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,
  ...
}:

let
  cfg = config.services.emile.remarvin;
in
with lib;
{
  options.services.emile.remarvin = {
    enable = mkEnableOption "Enable remarvin";

    # ip and port to listen on
    host = mkOption {
      type = types.str;
      default = "127.0.0.1";
      example = "0.0.0.0";
      description = "The host the service listens on";
    };

    port = mkOption {
      type = types.int;
      default = 8080;
      example = 8080;
      description = "The port the service listens on";
    };

    # env vars with secrets to set
    username = mkOption {
      type = types.str;
      default = "";
      example = "remarvin";
      description = "The username of the bot (without @ or homeserver)";
    };

    homeserver = mkOption {
      type = types.str;
      default = "";
      example = "matrix.org";
      description = "The homeserver to use";
    };

    accesstoken = mkOption {
      type = types.str;
      default = "";
      example = "syt_bWFy2mluX34lc3Qx_VARzpUOQIzyzCHunCDnd_1hbPka";
      description = "The accesstoken used to authenticat (element web > settings > help & about > advanced > access token)";
    };
  };

  config = mkIf cfg.enable {
    systemd.services.remarvin = {
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        RestartSec = 5;
        Restart = "always";
      };
      environment = {
        SESSION_KEY = cfg.sessionKey;
        SALT = cfg.salt;
        VERSION = pkgs.r2wars-web.version;
      };
      path = [ pkgs.remarvin ];
      serviceConfig.ExecStart = "${pkgs.remarvin}/bin/remarvin -homeserver ${cfg.homeserver} -username ${cfg.username} -accesstoken ${cfg.accesstoken}";
    };
  };
}