1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
10 drv = pkgs.sourcehut.mansrht;
13 options.services.sourcehut.man = {
26 Port on which the "man" module should listen.
32 default = "man.sr.ht";
34 PostgreSQL database name for man.sr.ht.
38 statePath = mkOption {
40 default = "${cfg.statePath}/mansrht";
42 State path for man.sr.ht.
47 config = with scfg; lib.mkIf (cfg.enable && elem "man" cfg.services) {
51 assertion = hasAttrByPath [ "git.sr.ht" "oauth-client-id" ] cfgIni;
52 message = "man.sr.ht needs access to git.sr.ht.";
61 description = "man.sr.ht user";
70 services.postgresql = {
72 local ${database} ${user} trust
74 ensureDatabases = [ database ];
78 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
85 "d ${statePath} 0750 ${user} ${user} -"
88 services.mansrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
89 after = [ "postgresql.service" "network.target" ];
90 requires = [ "postgresql.service" ];
91 wantedBy = [ "multi-user.target" ];
93 description = "man.sr.ht website service";
95 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
99 services.sourcehut.settings = {
100 # URL man.sr.ht is being served at (protocol://domain)
101 "man.sr.ht".origin = mkDefault "http://man.${cfg.originBase}";
102 # Address and port to bind the debug server to
103 "man.sr.ht".debug-host = mkDefault "0.0.0.0";
104 "man.sr.ht".debug-port = mkDefault port;
105 # Configures the SQLAlchemy connection string for the database.
106 "man.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
107 # man.sr.ht's OAuth client ID and secret for meta.sr.ht
108 # Register your client at meta.example.org/oauth
109 "man.sr.ht".oauth-client-id = mkDefault null;
110 "man.sr.ht".oauth-client-secret = mkDefault null;
113 services.nginx.virtualHosts."man.${cfg.originBase}" = {
115 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
116 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
117 locations."/static".root = "${pkgs.sourcehut.mansrht}/${pkgs.sourcehut.python.sitePackages}/mansrht";