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