summaryrefslogtreecommitdiffstats
path: root/modules/charybdis/default.nix
blob: 337ea132033fb406e62f5aac09816a440052c7ac (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
{ config, lib, mylib, pkgs, ... }@args: let
  cfg = config.tv.charybdis;
in {
  options.tv.charybdis = {
    enable = lib.mkEnableOption "tv.charybdis";
    motd = lib.mkOption {
      type = lib.types.str;
      default = "/join #retiolum";
    };
    port = lib.mkOption {
      type = lib.types.int;
      default = 6667;
    };
    ssl_cert = lib.mkOption {
      type = lib.types.path;
    };
    ssl_dh_params = lib.mkOption {
      type = mylib.types.absolute-pathname;
      default = "${config.krebs.secret.directory}/charybdis.dh.pem";
    };
    ssl_private_key = lib.mkOption {
      type = mylib.types.absolute-pathname;
      default = "${config.krebs.secret.directory}/charybdis.key.pem";
    };
    sslport = lib.mkOption {
      type = lib.types.int;
      default = 6697;
    };
    user = lib.mkOption {
      type = mylib.types.user;
      default = {
        name = "charybdis";
        home = "/var/lib/charybdis";
      };
    };
  };
  config = lib.mkIf cfg.enable {

    environment.etc."charybdis-ircd.motd".text = cfg.motd;

    krebs.systemd.services.charybdis = {};

    systemd.services.charybdis = {
      wantedBy = [ "multi-user.target" ];
      after = [ "network-online.target" ];
      environment = {
        BANDB_DBPATH = "${cfg.user.home}/ban.db";
      };
      serviceConfig = {
        SyslogIdentifier = "charybdis";
        User = cfg.user.name;
        PrivateTmp = true;
        Restart = "always";
        ExecStartPre = [
          "${pkgs.coreutils}/bin/ln -s /etc/charybdis-ircd.motd /tmp/ircd.motd"
          "${pkgs.coreutils}/bin/ln -s \${CREDENTIALS_DIRECTORY} /tmp/credentials"
        ];
        ExecStart = toString [
          "${pkgs.charybdis}/bin/charybdis"
            "-configfile ${import ./config.nix args}"
            "-foreground"
            "-logfile /dev/stderr"
        ];
        LoadCredential = [
          "ssl_dh_params:${cfg.ssl_dh_params}"
          "ssl_private_key:${cfg.ssl_private_key}"
        ];
      };
    };

    users.users.${cfg.user.name} = {
      inherit (cfg.user) home name uid;
      createHome = true;
      group = cfg.user.name;
      isSystemUser = true;
    };

    users.groups.${cfg.user.name} = {};
  };
}