1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
10 drv = pkgs.sourcehut.hubsrht;
13 options.services.sourcehut.hub = {
26 Port on which the "hub" module should listen.
32 default = "hub.sr.ht";
34 PostgreSQL database name for hub.sr.ht.
38 statePath = mkOption {
40 default = "${cfg.statePath}/hubsrht";
42 State path for hub.sr.ht.
47 config = with scfg; lib.mkIf (cfg.enable && elem "hub" cfg.services) {
53 description = "hub.sr.ht user";
62 services.postgresql = {
64 local ${database} ${user} trust
66 ensureDatabases = [ database ];
70 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
77 "d ${statePath} 0750 ${user} ${user} -"
80 services.hubsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
81 after = [ "postgresql.service" "network.target" ];
82 requires = [ "postgresql.service" ];
83 wantedBy = [ "multi-user.target" ];
85 description = "hub.sr.ht website service";
87 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
91 services.sourcehut.settings = {
92 # URL hub.sr.ht is being served at (protocol://domain)
93 "hub.sr.ht".origin = mkDefault "http://hub.${cfg.originBase}";
94 # Address and port to bind the debug server to
95 "hub.sr.ht".debug-host = mkDefault "0.0.0.0";
96 "hub.sr.ht".debug-port = mkDefault port;
97 # Configures the SQLAlchemy connection string for the database.
98 "hub.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
99 # Set to "yes" to automatically run migrations on package upgrade.
100 "hub.sr.ht".migrate-on-upgrade = mkDefault "yes";
101 # hub.sr.ht's OAuth client ID and secret for meta.sr.ht
102 # Register your client at meta.example.org/oauth
103 "hub.sr.ht".oauth-client-id = mkDefault null;
104 "hub.sr.ht".oauth-client-secret = mkDefault null;
107 services.nginx.virtualHosts."${cfg.originBase}" = {
109 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
110 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
111 locations."/static".root = "${pkgs.sourcehut.hubsrht}/${pkgs.sourcehut.python.sitePackages}/hubsrht";
113 services.nginx.virtualHosts."hub.${cfg.originBase}" = {
114 globalRedirect = "${cfg.originBase}";