nixos-config/nixos/machines/chungus/media-curl.nix

59 lines
1.2 KiB
Nix
Raw Normal View History

2023-10-20 08:01:09 +02:00
{ config, pkgs, lib, ... }:
with lib;
let
configuration = {
#Chaospott37C3Tickets = rec {
# url = "https://md.chaospott.de/171s8-_cQCyX_tUca_Jxqw/download";
# target = "/media/curl/37C3";
# options = [
# "-o $( date +%H:%M:%S )-TicketPlaning.md"
# ];
#};
2023-10-20 09:03:12 +02:00
StableConfussion = {
url = "http://stable-confusion.r/outputs/";
target = "/media/curl/stable-confusion";
options = [ "--mirror" "--quiet" ];
2023-10-20 09:03:12 +02:00
command = "wget";
2023-10-20 08:01:09 +02:00
};
2023-10-20 08:01:09 +02:00
};
downloadScript =
name: { url
2023-10-20 09:03:12 +02:00
, options
2023-10-20 08:01:09 +02:00
, target
2023-10-20 09:03:12 +02:00
, command ? "curl"
2023-10-20 08:01:09 +02:00
}: pkgs.writers.writeDash "curl-script-${name}" ''
mkdir -p "${target}"
2023-10-20 09:03:12 +02:00
cd "${target}"
${command} ${concatStringsSep " " options} "${url}"
2023-10-20 08:01:09 +02:00
'';
in
{
systemd.services.curl-download = {
after = [ "network.target" ];
2023-10-20 09:03:12 +02:00
path = [ pkgs.curl pkgs.wget ];
2023-10-20 08:01:09 +02:00
serviceConfig = {
User = "media";
Group = "media";
};
script = (concatStringsSep "\n"
(mapAttrsToList downloadScript configuration)
);
};
systemd.timers.curl-download = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "hourly";
Persistent = "true";
};
};
}