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 = {
15 enable = mkEnableOption "meta service";
29 Port on which the "meta" module should listen.
35 default = "meta.sr.ht";
37 PostgreSQL database name for meta.sr.ht.
42 config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
46 assertion = with cfgIni."meta.sr.ht::billing"; enabled == "yes" -> (stripe-public-key != null && stripe-secret-key != null);
47 message = "If meta.sr.ht::billing is enabled, the keys should be defined.";
56 description = "meta.sr.ht user";
65 services.cron.systemCronJobs = [ "0 0 * * * ${cfg.python}/bin/metasrht-daily" ];
66 services.postgresql = {
68 local ${database} ${user} trust
70 ensureDatabases = [ database ];
74 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
82 # Configure client(s) as "preauthorized"
83 ${concatMapStringsSep "\n\n"
85 if ! test -e "${statePath}/${srv}.oauth" || [ "$(cat ${statePath}/${srv}.oauth)" != "${cfgIni.${srv}.oauth-client-id}" ]; then
86 # Configure ${srv}'s OAuth client as "preauthorized"
88 -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni.${srv}.oauth-client-id}'"
90 printf "%s" "${cfgIni.${srv}.oauth-client-id}" > "${statePath}/${srv}.oauth"
93 (builtins.attrNames (filterAttrs (k: v:
94 let srv = builtins.match "^([a-z]*)\\.sr\\.ht$" k; in
95 srv != null && cfg.${head srv}.enable &&
96 ((v.oauth-client-id or null) != null)
100 metasrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
101 after = [ "postgresql.service" "network.target" ];
102 requires = [ "postgresql.service" ];
103 wantedBy = [ "multi-user.target" ];
105 description = "meta.sr.ht website service";
107 preStart = commonPreStart;
109 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
112 metasrht-api = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
113 after = [ "postgresql.service" "network.target" ];
114 requires = [ "postgresql.service" ];
115 wantedBy = [ "multi-user.target" ];
117 description = "meta.sr.ht api service";
119 preStart = commonPreStart;
121 serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b :${toString (port + 100)}";
124 metasrht-webhooks = {
125 after = [ "postgresql.service" "network.target" ];
126 requires = [ "postgresql.service" ];
127 wantedBy = [ "multi-user.target" ];
129 description = "meta.sr.ht webhooks service";
134 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
141 services.nginx.virtualHosts."meta.${cfg.originBase}" = {
143 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
144 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
145 locations."/static".root = "${pkgs.sourcehut.metasrht}/${pkgs.sourcehut.python.sitePackages}/metasrht";
148 environment.systemPackages = [
149 (pkgs.linkFarm "metasrht" [
150 { name = "bin/metasrht-manageuser";
151 path = "${cfg.python}/bin/metasrht-manageuser";