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

71 lines
1.2 KiB
Nix
Raw Normal View History

2024-08-29 03:26:04 +02:00
{
config,
pkgs,
lib,
...
}:
2023-10-20 08:01:09 +02:00
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";
2024-08-29 03:26:04 +02:00
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 =
2024-08-29 03:26:04 +02:00
name:
{
url,
options,
target,
command ? "curl",
}:
pkgs.writers.writeDash "curl-script-${name}" ''
2023-10-20 08:01:09 +02:00
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" ];
2024-08-29 03:26:04 +02:00
path = [
pkgs.curl
pkgs.wget
];
2023-10-20 08:01:09 +02:00
serviceConfig = {
User = "media";
Group = "media";
};
2024-08-29 03:26:04 +02:00
script = (concatStringsSep "\n" (mapAttrsToList downloadScript configuration));
2023-10-20 08:01:09 +02:00
};
systemd.timers.curl-download = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "hourly";
Persistent = "true";
};
};
}