in
{
options.services.sourcehut.meta = {
+ enable = mkEnableOption "meta service";
+
user = mkOption {
type = types.str;
default = "metasrht";
};
};
- config = with scfg; lib.mkIf (cfg.enable && elem "meta" cfg.services) {
+ config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
assertions =
[
{
};
};
- services.cron.systemCronJobs = [ "0 0 * * * ${cfg.python}/bin/metasrht-daily" ];
services.postgresql = {
authentication = ''
local ${database} ${user} trust
'')
(builtins.attrNames (filterAttrs (k: v:
let srv = builtins.match "^([a-z]*)\\.sr\\.ht$" k; in
- srv != null && elem (head srv) cfg.services &&
+ srv != null && cfg.${head srv}.enable &&
((v.oauth-client-id or null) != null)
) cfg.settings))}
'';
metasrht-api = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
after = [ "postgresql.service" "network.target" ];
requires = [ "postgresql.service" ];
- wantedBy = [ "multi-user.target" ];
+ wantedBy = [ "metasrht.service" ];
description = "meta.sr.ht api service";
serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b :${toString (port + 100)}";
};
+ metasrht-daily = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
+ after = [ "metasrht.service" ];
+ requires = [ "metasrht.service" ];
+
+ description = "meta.sr.ht daily service";
+
+ serviceConfig.Type = mkForce "oneshot";
+ serviceConfig.Restart = mkForce "no";
+ serviceConfig.ExecStart = "${cfg.python}/bin/metasrht-daily";
+ };
+
metasrht-webhooks = {
after = [ "postgresql.service" "network.target" ];
requires = [ "postgresql.service" ];
- wantedBy = [ "multi-user.target" ];
+ wantedBy = [ "multi-user.service" ];
description = "meta.sr.ht webhooks service";
serviceConfig = {
};
};
+ systemd.timers = {
+ metasrht-daily = {
+ description = "metasrht daily timer";
+ wantedBy = [ "timers.target" ];
+ timerConfig = {
+ OnCalendar = "daily";
+ Persistent = true;
+ AccuracySec = "1h";
+ };
+ };
+ };
+
services.nginx.virtualHosts."meta.${cfg.originBase}" = {
forceSSL = true;
locations."/".proxyPass = "http://${cfg.address}:${toString port}";
- locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
+ locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
locations."/static".root = "${pkgs.sourcehut.metasrht}/${pkgs.sourcehut.python.sitePackages}/metasrht";
};
+
+ environment.systemPackages = [
+ (pkgs.linkFarm "metasrht" [
+ { name = "bin/metasrht-manageuser";
+ path = "${cfg.python}/bin/metasrht-manageuser";
+ }
+ ])
+ ];
};
}