1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
8 iniKey = "dispatch.sr.ht";
10 drv = pkgs.sourcehut.dispatchsrht;
13 options.services.sourcehut.dispatch = {
16 default = "dispatchsrht";
18 User for dispatch.sr.ht.
26 Port on which the "dispatch" module should listen.
32 default = "dispatch.sr.ht";
34 PostgreSQL database name for dispatch.sr.ht.
38 statePath = mkOption {
40 default = "${cfg.statePath}/dispatchsrht";
42 State path for dispatch.sr.ht.
47 config = with scfg; lib.mkIf (cfg.enable && elem "dispatch" cfg.services) {
54 description = "dispatch.sr.ht user";
63 services.postgresql = {
65 local ${database} ${user} trust
67 ensureDatabases = [ database ];
71 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
78 "d ${statePath} 0750 ${user} ${user} -"
81 services.dispatchsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
82 after = [ "postgresql.service" "network.target" ];
83 requires = [ "postgresql.service" ];
84 wantedBy = [ "multi-user.target" ];
86 description = "dispatch.sr.ht website service";
88 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
92 services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
94 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
95 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
96 locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";