1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
9 statePath = "/var/lib/sourcehut/metasrht";
11 drv = pkgs.sourcehut.metasrht;
14 options.services.sourcehut.meta = {
27 Port on which the "meta" module should listen.
33 default = "meta.sr.ht";
35 PostgreSQL database name for meta.sr.ht.
40 config = with scfg; lib.mkIf (cfg.enable && elem "meta" cfg.services) {
44 assertion = with cfgIni."meta.sr.ht::billing"; enabled == "yes" -> (stripe-public-key != null && stripe-secret-key != null);
45 message = "If meta.sr.ht::billing is enabled, the keys should be defined.";
54 description = "meta.sr.ht user";
63 services.cron.systemCronJobs = [ "0 0 * * * ${cfg.python}/bin/metasrht-daily" ];
64 services.postgresql = {
66 local ${database} ${user} trust
68 ensureDatabases = [ database ];
72 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
80 # Configure client(s) as "preauthorized"
81 ${concatMapStringsSep "\n\n"
83 if ! test -e "${statePath}/${attr}.oauth" || [ "$(cat ${statePath}/${attr}.oauth)" != "${cfgIni."${attr}".oauth-client-id}" ]; then
84 # Configure ${attr}'s OAuth client as "preauthorized"
86 -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni."${attr}".oauth-client-id}'"
88 printf "%s" "${cfgIni."${attr}".oauth-client-id}" > "${statePath}/${attr}.oauth"
91 (builtins.attrNames (filterAttrs
92 (k: v: !(hasInfix "::" k) && (v.oauth-client-id or null) != null)
96 metasrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
97 after = [ "postgresql.service" "network.target" ];
98 requires = [ "postgresql.service" ];
99 wantedBy = [ "multi-user.target" ];
101 description = "meta.sr.ht website service";
103 preStart = commonPreStart;
105 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
108 metasrht-api = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
109 after = [ "postgresql.service" "network.target" ];
110 requires = [ "postgresql.service" ];
111 wantedBy = [ "multi-user.target" ];
113 description = "meta.sr.ht api service";
115 preStart = commonPreStart;
117 serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b :${toString (port + 100)}";
120 metasrht-webhooks = {
121 after = [ "postgresql.service" "network.target" ];
122 requires = [ "postgresql.service" ];
123 wantedBy = [ "multi-user.target" ];
125 description = "meta.sr.ht webhooks service";
130 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
137 services.nginx.virtualHosts."meta.${cfg.originBase}" = {
139 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
140 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
141 locations."/static".root = "${pkgs.sourcehut.metasrht}/${pkgs.sourcehut.python.sitePackages}/metasrht";