1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.go-neb;
7
8 configFile = pkgs.writeText "config.yml" (builtins.toJSON cfg.config);
9in {
10 options.services.go-neb = {
11 enable = mkEnableOption "Extensible matrix bot written in Go";
12
13 bindAddress = mkOption {
14 type = types.str;
15 description = "Port (and optionally address) to listen on.";
16 default = ":4050";
17 };
18
19 baseUrl = mkOption {
20 type = types.str;
21 description = "Public-facing endpoint that can receive webhooks.";
22 };
23
24 config = mkOption {
25 type = types.uniq types.attrs;
26 description = ''
27 Your <filename>config.yaml</filename> as a Nix attribute set.
28 See <link xlink:href="https://github.com/matrix-org/go-neb/blob/master/config.sample.yaml">config.sample.yaml</link>
29 for possible options.
30 '';
31 };
32 };
33
34 config = mkIf cfg.enable {
35 systemd.services.go-neb = {
36 description = "Extensible matrix bot written in Go";
37 after = [ "network.target" ];
38 wantedBy = [ "multi-user.target" ];
39 environment = {
40 BASE_URL = cfg.baseUrl;
41 BIND_ADDRESS = cfg.bindAddress;
42 CONFIG_FILE = configFile;
43 };
44
45 serviceConfig = {
46 ExecStart = "${pkgs.go-neb}/bin/go-neb";
47 DynamicUser = true;
48 };
49 };
50 };
51
52 meta.maintainers = with maintainers; [ hexa maralorn ];
53}