1 # Email setup is fairly involved, useful references:
2 # https://drewdevault.com/2018/08/05/Local-mail-server.html
4 { config, lib, pkgs, ... }:
8 cfg = config.services.sourcehut;
11 iniKey = "lists.sr.ht";
13 rcfg = config.services.redis;
14 drv = pkgs.sourcehut.listssrht;
17 options.services.sourcehut.lists = {
20 default = "listssrht";
30 Port on which the "lists" module should listen.
36 default = "lists.sr.ht";
38 PostgreSQL database name for lists.sr.ht.
42 statePath = mkOption {
44 default = "${cfg.statePath}/listssrht";
46 State path for lists.sr.ht.
51 config = with scfg; lib.mkIf (cfg.enable && elem "lists" cfg.services) {
57 extraGroups = [ "postfix" ];
58 description = "lists.sr.ht user";
66 services.postgresql = {
68 local ${database} ${user} trust
70 ensureDatabases = [ database ];
74 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
81 "d ${statePath} 0750 ${user} ${user} -"
85 listssrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
86 after = [ "postgresql.service" "network.target" ];
87 requires = [ "postgresql.service" ];
88 wantedBy = [ "multi-user.target" ];
90 description = "lists.sr.ht website service";
92 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
96 after = [ "postgresql.service" "network.target" ];
97 requires = [ "postgresql.service" ];
98 wantedBy = [ "multi-user.target" ];
100 description = "lists.sr.ht process service";
105 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.process worker --loglevel INFO --pool eventlet";
110 after = [ "postgresql.service" "network.target" ];
111 requires = [ "postgresql.service" ];
112 wantedBy = [ "multi-user.target" ];
114 description = "lists.sr.ht process service";
119 ExecStart = "${cfg.python}/bin/listssrht-lmtp";
124 listssrht-webhooks = {
125 after = [ "postgresql.service" "network.target" ];
126 requires = [ "postgresql.service" ];
127 wantedBy = [ "multi-user.target" ];
129 description = "lists.sr.ht webhooks service";
134 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
140 services.sourcehut.settings = {
141 # URL lists.sr.ht is being served at (protocol://domain)
142 "lists.sr.ht".origin = mkDefault "http://lists.${cfg.originBase}";
143 # Address and port to bind the debug server to
144 "lists.sr.ht".debug-host = mkDefault "0.0.0.0";
145 "lists.sr.ht".debug-port = mkDefault port;
146 # Configures the SQLAlchemy connection string for the database.
147 "lists.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
148 # lists.sr.ht's OAuth client ID and secret for meta.sr.ht
149 # Register your client at meta.example.org/oauth
150 "lists.sr.ht".oauth-client-id = mkDefault null;
151 "lists.sr.ht".oauth-client-secret = mkDefault null;
152 # Outgoing email for notifications generated by users
153 "lists.sr.ht".notify-from = mkDefault "CHANGEME@example.org";
154 # The redis connection used for the webhooks worker
155 "lists.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/2";
156 # The redis connection used for the celery worker
157 "lists.sr.ht".redis = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/4";
159 "lists.sr.ht".network-key = mkDefault null;
161 "lists.sr.ht".allow-new-lists = mkDefault "no";
163 "lists.sr.ht".posting-domain = mkDefault "lists.${cfg.originBase}";
165 # Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
166 # Alternatively, specify IP:PORT and an SMTP server will be run instead.
167 "lists.sr.ht::worker".sock = mkDefault "/tmp/lists.sr.ht-lmtp.sock";
168 # The lmtp daemon will make the unix socket group-read/write for users in this
170 "lists.sr.ht::worker".sock-group = mkDefault "postfix";
171 "lists.sr.ht::worker".reject-url = mkDefault "https://man.sr.ht/lists.sr.ht/etiquette.md";
172 "lists.sr.ht::worker".reject-mimetypes = mkDefault "text/html";
176 services.nginx.virtualHosts."lists.${cfg.originBase}" = {
178 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
179 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
180 locations."/static".root = "${pkgs.sourcehut.listssrht}/${pkgs.sourcehut.python.sitePackages}/listssrht";