# Email setup is fairly involved, useful references: # https://drewdevault.com/2018/08/05/Local-mail-server.html { config, lib, pkgs, ... }: with lib; let cfg = config.services.sourcehut; cfgIni = cfg.settings; scfg = cfg.lists; iniKey = "lists.sr.ht"; statePath = "/var/lib/sourcehut/listssrht"; rcfg = config.services.redis; drv = pkgs.sourcehut.listssrht; in { options.services.sourcehut.lists = { enable = mkEnableOption "lists service"; user = mkOption { type = types.str; default = "listssrht"; description = '' User for lists.sr.ht. ''; }; port = mkOption { type = types.port; default = 5006; description = '' Port on which the "lists" module should listen. ''; }; database = mkOption { type = types.str; default = "lists.sr.ht"; description = '' PostgreSQL database name for lists.sr.ht. ''; }; }; config = with scfg; lib.mkIf (cfg.enable && scfg.enable) { users = { users = { "${user}" = { isSystemUser = true; group = user; extraGroups = [ "postfix" ]; description = "lists.sr.ht user"; }; }; groups = { "${user}" = { }; }; }; services.postgresql = { authentication = '' local ${database} ${user} trust ''; ensureDatabases = [ database ]; ensureUsers = [ { name = user; ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; }; } ]; }; systemd = { services = { listssrht = import ./service.nix { inherit config pkgs lib; initDB = true; } scfg drv iniKey { after = [ "postgresql.service" "network.target" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; description = "lists.sr.ht website service"; serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}"; }; listssrht-process = { after = [ "postgresql.service" "network.target" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; description = "lists.sr.ht process service"; serviceConfig = { Type = "simple"; User = user; Restart = "always"; ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.process worker --loglevel INFO --pool eventlet"; }; }; listssrht-lmtp = { after = [ "postgresql.service" "network.target" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; description = "lists.sr.ht process service"; serviceConfig = { Type = "simple"; User = user; Restart = "always"; ExecStart = "${cfg.python}/bin/listssrht-lmtp"; }; }; listssrht-webhooks = { after = [ "postgresql.service" "network.target" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; description = "lists.sr.ht webhooks service"; serviceConfig = { Type = "simple"; User = user; Restart = "always"; ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet"; }; }; }; }; services.nginx.virtualHosts."lists.${cfg.originBase}" = { forceSSL = true; locations."/".proxyPass = "http://${cfg.address}:${toString port}"; locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin; locations."/static".root = "${pkgs.sourcehut.listssrht}/${pkgs.sourcehut.python.sitePackages}/listssrht"; }; }; }