summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/ergo.nix
blob: 14f85c4d7d04cda1b85983dde4f37dfaa2212a3c (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{ config, lib, pkgs, ... }:

let
  inherit (lib) mkEnableOption mkIf mkOption types;
  inherit (pkgs) coreutils ergo;
  cfg = config.krebs.ergo;

  configFile = pkgs.writeText "ergo.conf" (builtins.toJSON cfg.config);
in

{

  ###### interface

  options = {

    krebs.ergo = {

      enable = mkEnableOption "Ergo IRC daemon";

      config = mkOption {
        type = (pkgs.formats.json {}).type;
        description = ''
          Ergo IRC daemon configuration file.
        '';
        default = {
          network = {
            name = "krebstest";
          };
          server = {
            name = "${config.networking.hostName}.r";
            listeners = {
              ":6667" = {};
            };
            casemapping = "permissive";
            enforce-utf = true;
            lookup-hostnames = false;
            ip-cloaking = {
              enabled = false;
            };
            forward-confirm-hostnames = false;
            check-ident = false;
            relaymsg = {
              enabled = false;
            };
            max-sendq = "1M";
            ip-limits = {
              count = false;
              throttle = false;
            };
          };
          datastore = {
            path = "${cfg.statedir}/ircd.db";
          };
          accounts = {
            authentication-enabled = true;
            registration = {
              enabled = true;
              email-verification = {
                enabled = false;
              };
            };
          };
          channels = {
            default-modes = "+nt";
          };
          limits = {
            nicklen = 32;
            identlen = 20;
            channellen = 64;
            awaylen = 390;
            kicklen = 390;
            topiclen = 390;
          };
        };
      };

      statedir = mkOption {
        type = types.path;
        default = "/var/lib/ergo";
        description = ''
          Location of the state directory of ergo.
        '';
      };

      user = mkOption {
        type = types.str;
        default = "ergo";
        description = ''
          Ergo IRC daemon user.
        '';
      };

      group = mkOption {
        type = types.str;
        default = "ergo";
        description = ''
          Ergo IRC daemon group.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf cfg.enable ({
    users.users.${cfg.user} = {
      description = "Ergo IRC daemon user";
      uid = config.ids.uids.ircd;
      group = cfg.group;
    };

    users.groups.${cfg.group} = {
      gid = config.ids.gids.ircd;
    };

    systemd.tmpfiles.rules = [
      "d ${cfg.statedir} - ${cfg.user} ${cfg.group} - -"
    ];

    systemd.services.ergo = {
      description = "Ergo IRC daemon";
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStartPre = "${ergo}/bin/ergo initdb --conf ${configFile}";
        ExecStart = "${ergo}/bin/ergo run --conf ${configFile}";
        Group = cfg.group;
        User = cfg.user;
      };
    };

  });
}