{ config, lib, pkgs, ... }: with lib; let cfg = config.services.sourcehut; cfgIni = cfg.settings; scfg = cfg.dispatch; iniKey = "dispatch.sr.ht"; statePath = "/var/lib/sourcehut/dispatchsrht"; drv = pkgs.sourcehut.dispatchsrht; in { options.services.sourcehut.dispatch = { user = mkOption { type = types.str; default = "dispatchsrht"; description = '' User for dispatch.sr.ht. ''; }; port = mkOption { type = types.port; default = 5005; description = '' Port on which the "dispatch" module should listen. ''; }; database = mkOption { type = types.str; default = "dispatch.sr.ht"; description = '' PostgreSQL database name for dispatch.sr.ht. ''; }; }; config = with scfg; lib.mkIf (cfg.enable && elem "dispatch" cfg.services) { users = { users = { "${user}" = { isSystemUser = true; group = user; description = "dispatch.sr.ht user"; }; }; groups = { "${user}" = { }; }; }; services.postgresql = { authentication = '' local ${database} ${user} trust ''; ensureDatabases = [ database ]; ensureUsers = [ { name = user; ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; }; } ]; }; systemd = { services.dispatchsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey { after = [ "postgresql.service" "network.target" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; description = "dispatch.sr.ht website service"; serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}"; }; }; services.nginx.virtualHosts."dispatch.${cfg.originBase}" = { forceSSL = true; locations."/".proxyPass = "http://${cfg.address}:${toString port}"; locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}"; locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht"; }; }; }