about summary refs log tree commit diff
path: root/nix/hosts/corrino/www/irc.emile.space.nix
blob: f738d6231f6ae887ee0fce830445bf6f5187965e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{ config, ... }:

{
	# Create a tls cert for the irc server
	security.acme.certs = {
		"irc.emile.space" = {
			webroot = "/var/lib/acme/acme-challenge/";
			email = "acme@emile.space";
			postRun = "cp fullchain.pem /home/ergo/ && cp key.pem /home/ergo && chown ergo:ergo /home/ergo/*.pem && systemctl reload ergo.service";
		};
	};

	# Allow ergo to access the created cert
	# The systemd server runs using a dynamic user, so the below inserts the .pem files
	#   into "/run/credentials/ergochat.service/key.pem"
	systemd.services.ergochat.serviceConfig = {
		LoadCredential = [
			"fullchain.pem:/var/lib/acme/irc.emile.space/fullchain.pem"
			"key.pem:/var/lib/acme/irc.emile.space/key.pem"
		];
	};

	# allow connections to the port from the "outside"
  networking.firewall.allowedTCPPorts = [ config.emile.ports.irc.ssl ];

	services.ergochat = {
		enable = true;

		# https://raw.githubusercontent.com/ergochat/ergo/master/default.yaml
		settings = {
		  accounts = {
		    authentication-enabled = true;
		    multiclient = {
		      allowed-by-default = true;
		      always-on = "opt-out";
		      auto-away = "opt-out";
		      enabled = true;
		    };
		    registration = {
		      enabled = true;
		      allow-before-connect = true;
		      bcrypt-cost = 4;
		      email-verification = {
		        enabled = false;
		      };
		      throttling = {
		        duration = "10m";
		        enabled = true;
		        max-attempts = 30;
		      };
		    };
		  };
		  channels = {
		    default-modes = "+ntC";
		    registration = {
		      enabled = true;
		    };
		  };
		  datastore = {
		    autoupgrade = true;
		    path = "/var/lib/ergo/ircd.db";
		  };
		  history = {
		    enabled = true;
		    autoreplay-on-join = 0;
		    autoresize-window = "3d";
		    channel-length = 2048;
		    chathistory-maxmessages = 100;
		    client-length = 256;
		    restrictions = {
		      expire-time = "1w";
		      grace-period = "1h";
		      query-cutoff = "none";
		    };
		    retention = {
		      allow-individual-delete = false;
		      enable-account-indexing = false;
		    };
		    tagmsg-storage = {
		      default = false;
		      whitelist = [
		        "+draft/react"
		        "+react"
		      ];
		    };
		    znc-maxmessages = 2048;
		  };
		  limits = {
		    awaylen = 390;
		    channellen = 64;
		    identlen = 20;
		    kicklen = 390;
		    nicklen = 32;
		    topiclen = 390;
		  };
		  network = {
		    name = "emilespace";
		  };
		  server = {
		    casemapping = "permissive";
		    check-ident = false;
		    enforce-utf = true;
		    forward-confirm-hostnames = false;
		    ip-cloaking = {
		      enabled = false;
		    };
		    ip-limits = {
		      count = false;
		      throttle = false;
		    };
		    listeners = {
					# sts only port
		      ":6667".sts-only = true;

					# loopback listeners
		      # "127.0.0.1:6668" = {};
		      # "[::]:6668" = {};

		      ":${toString config.emile.ports.irc.ssl}" = {
						tls = {
							cert = "/run/credentials/ergochat.service/fullchain.pem";
							key = "/run/credentials/ergochat.service/key.pem";
						};

						# for cloud load balancers setting a PROXY header, NOT reverse proxies...
						proxy = false;

						min-tls-version = 1.2;
					};
		    };
		    lookup-hostnames = false;
		    max-sendq = "1M";
		    name = "emile.space";
		    relaymsg = {
		      enabled = false;
		    };
				sts = {
					enabled = true; # redirect from plain to tls if supported

					# how long clients should be forced to use TLS for.
					# (Emile): no clue why, can I set something like \infty here?
					duration = "12m";

				};
		  };
			logging = [
				{
					method = "stderr";
					type = "* -userinput -useroutput";
					level = "debug";
				}
			];
		};
	};
}