1
1
Fork 0
nixos/options/custom/services/piped.nix
Myned 311aa76294
custom: add domain option
Signed-off-by: Myned <dev@bjork.tech>
2025-02-09 18:45:10 -06:00

47 lines
1.2 KiB
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
curl = "${pkgs.curl}/bin/curl";
docker = "${pkgs.docker}/bin/docker";
parallel = "${pkgs.parallel}/bin/parallel";
cfg = config.custom.services.piped;
in {
options.custom.services.piped.enable = mkOption {default = false;};
config = mkIf cfg.enable {
# https://wiki.nixos.org/wiki/Systemd/timers
# Manually fetch channels in background
# TODO: Remove when fixed upstream
# https://github.com/TeamPiped/Piped/issues/1130
systemd = {
services."fetch-channels" = {
script = ''
${docker} compose --file /docker/piped/docker-compose.yml exec postgres \
psql \
--username piped \
--dbname piped \
--tuples-only \
--no-align \
--quiet \
--command 'SELECT DISTINCT(channel) FROM users_subscribed' | \
${parallel} ${curl} --silent --output /dev/null 'https://pipedapi.${config.custom.domain}/channel/{}'
'';
};
timers."fetch-channels" = {
wantedBy = ["timers.target"];
timerConfig = {
OnBootSec = "1h";
OnUnitActiveSec = "1h";
};
};
};
};
}