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}/${srv}.oauth" || [ "$(cat ${statePath}/${srv}.oauth)" != "${cfgIni.${srv}.oauth-client-id}" ]; then
84 # Configure ${srv}'s OAuth client as "preauthorized"
86 -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni.${srv}.oauth-client-id}'"
88 printf "%s" "${cfgIni.${srv}.oauth-client-id}" > "${statePath}/${srv}.oauth"
91 (builtins.attrNames (filterAttrs (k: v:
92 let srv = builtins.match "^([a-z]*)\\.sr\\.ht$" k; in
93 srv != null && elem (head srv) cfg.services &&
94 ((v.oauth-client-id or null) != null)
98 metasrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
99 after = [ "postgresql.service" "network.target" ];
100 requires = [ "postgresql.service" ];
101 wantedBy = [ "multi-user.target" ];
103 description = "meta.sr.ht website service";
105 preStart = commonPreStart;
107 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
110 metasrht-api = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
111 after = [ "postgresql.service" "network.target" ];
112 requires = [ "postgresql.service" ];
113 wantedBy = [ "multi-user.target" ];
115 description = "meta.sr.ht api service";
117 preStart = commonPreStart;
119 serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b :${toString (port + 100)}";
122 metasrht-webhooks = {
123 after = [ "postgresql.service" "network.target" ];
124 requires = [ "postgresql.service" ];
125 wantedBy = [ "multi-user.target" ];
127 description = "meta.sr.ht webhooks service";
132 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
139 services.nginx.virtualHosts."meta.${cfg.originBase}" = {
141 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
142 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
143 locations."/static".root = "${pkgs.sourcehut.metasrht}/${pkgs.sourcehut.python.sitePackages}/metasrht";
146 environment.systemPackages = [
147 (pkgs.linkFarm "metasrht" [
148 { name = "bin/metasrht-manageuser";
149 path = "${cfg.python}/bin/metasrht-manageuser";