summary refs log tree commit diff
path: root/nixos/modules/services/networking/solanum.nix
blob: dc066a245494dc52bcea3d2755e138214c01ca8b (plain) (blame)
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
{ config, lib, pkgs, ... }:

let
  inherit (lib) mkEnableOption mkIf mkOption types;
  inherit (pkgs) solanum util-linux;
  cfg = config.services.solanum;

  configFile = pkgs.writeText "solanum.conf" cfg.config;
in

{

  ###### interface

  options = {

    services.solanum = {

      enable = mkEnableOption "Solanum IRC daemon";

      config = mkOption {
        type = types.str;
        default = ''
          serverinfo {
            name = "irc.example.com";
            sid = "1ix";
            description = "irc!";

            vhost = "0.0.0.0";
            vhost6 = "::";
          };

          listen {
            host = "0.0.0.0";
            port = 6667;
          };

          auth {
            user = "*@*";
            class = "users";
            flags = exceed_limit;
          };
          channel {
            default_split_user_count = 0;
          };
        '';
        description = ''
          Solanum IRC daemon configuration file.
          check <link xlink:href="https://github.com/solanum-ircd/solanum/blob/main/doc/reference.conf"/> for all options.
        '';
      };

      openFilesLimit = mkOption {
        type = types.int;
        default = 1024;
        description = ''
          Maximum number of open files. Limits the clients and server connections.
        '';
      };

      motd = mkOption {
        type = types.nullOr types.lines;
        default = null;
        description = ''
          Solanum MOTD text.

          Solanum will read its MOTD from <literal>/etc/solanum/ircd.motd</literal>.
          If set, the value of this option will be written to this path.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf cfg.enable (lib.mkMerge [
    {

      environment.etc."solanum/ircd.conf".source = configFile;

      systemd.services.solanum = {
        description = "Solanum IRC daemon";
        after = [ "network.target" ];
        wantedBy = [ "multi-user.target" ];
        reloadIfChanged = true;
        restartTriggers = [
          configFile
        ];
        serviceConfig = {
          ExecStart = "${solanum}/bin/solanum -foreground -logfile /dev/stdout -configfile /etc/solanum/ircd.conf -pidfile /run/solanum/ircd.pid";
          ExecReload = "${util-linux}/bin/kill -HUP $MAINPID";
          DynamicUser = true;
          User = "solanum";
          StateDirectory = "solanum";
          RuntimeDirectory = "solanum";
          LimitNOFILE = "${toString cfg.openFilesLimit}";
        };
      };

    }

    (mkIf (cfg.motd != null) {
      environment.etc."solanum/ircd.motd".text = cfg.motd;
    })
  ]);
}