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.sourcehut.settings = {
93 # URL dispatch.sr.ht is being served at (protocol://domain)
94 "dispatch.sr.ht".origin = mkDefault "http://dispatch.${cfg.originBase}";
95 # Address and port to bind the debug server to
96 "dispatch.sr.ht".debug-host = mkDefault "0.0.0.0";
97 "dispatch.sr.ht".debug-port = mkDefault port;
98 # Configures the SQLAlchemy connection string for the database.
99 "dispatch.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
100 # dispatch.sr.ht's OAuth client ID and secret for meta.sr.ht
101 # Register your client at meta.example.org/oauth
102 "dispatch.sr.ht".oauth-client-id = mkDefault null;
103 "dispatch.sr.ht".oauth-client-secret = mkDefault null;
106 "dispatch.sr.ht::github".oauth-client-id = mkDefault null;
107 "dispatch.sr.ht::github".oauth-client-secret = mkDefault null;
110 "dispatch.sr.ht::gitlab".enabled = mkDefault null;
111 "dispatch.sr.ht::gitlab".canonical-upstream = mkDefault "gitlab.com";
112 "dispatch.sr.ht::gitlab".repo-cache = mkDefault "./repo-cache";
113 # "dispatch.sr.ht::gitlab"."gitlab.com" = mkDefault "GitLab:application id:secret";
116 services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
118 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
119 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
120 locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";