1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
8 iniKey = "dispatch.sr.ht";
9 statePath = "/var/lib/sourcehut/dispatchsrht";
11 drv = pkgs.sourcehut.dispatchsrht;
14 options.services.sourcehut.dispatch = {
15 enable = mkEnableOption "dispatch service";
19 default = "dispatchsrht";
21 User for dispatch.sr.ht.
29 Port on which the "dispatch" module should listen.
35 default = "dispatch.sr.ht";
37 PostgreSQL database name for dispatch.sr.ht.
43 config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
50 description = "dispatch.sr.ht user";
59 services.postgresql = {
61 local ${database} ${user} trust
63 ensureDatabases = [ database ];
67 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
73 services.dispatchsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
74 after = [ "postgresql.service" "network.target" ];
75 requires = [ "postgresql.service" ];
76 wantedBy = [ "multi-user.target" ];
78 description = "dispatch.sr.ht website service";
80 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
84 services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
86 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
87 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
88 locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";