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 # Set to "yes" to automatically run migrations on package upgrade.
101 "dispatch.sr.ht".migrate-on-upgrade = mkDefault "yes";
102 # dispatch.sr.ht's OAuth client ID and secret for meta.sr.ht
103 # Register your client at meta.example.org/oauth
104 "dispatch.sr.ht".oauth-client-id = mkDefault null;
105 "dispatch.sr.ht".oauth-client-secret = mkDefault null;
108 "dispatch.sr.ht::github".oauth-client-id = mkDefault null;
109 "dispatch.sr.ht::github".oauth-client-secret = mkDefault null;
112 "dispatch.sr.ht::gitlab".enabled = mkDefault null;
113 "dispatch.sr.ht::gitlab".canonical-upstream = mkDefault "gitlab.com";
114 "dispatch.sr.ht::gitlab".repo-cache = mkDefault "./repo-cache";
115 # "dispatch.sr.ht::gitlab"."gitlab.com" = mkDefault "GitLab:application id:secret";
118 services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
120 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
121 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
122 locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";