nixos-config/machines/chungus/media-curl.nix
2024-06-07 22:56:52 +02:00

58 lines
1.2 KiB
Nix

{ 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"
# ];
#};
StableConfussion = {
url = "http://stable-confusion.r/outputs/";
target = "/media/curl/stable-confusion";
options = [ "--mirror" "--quiet" ];
command = "wget";
};
};
downloadScript =
name: { url
, options
, target
, command ? "curl"
}: pkgs.writers.writeDash "curl-script-${name}" ''
mkdir -p "${target}"
cd "${target}"
${command} ${concatStringsSep " " options} "${url}"
'';
in
{
systemd.services.curl-download = {
after = [ "network.target" ];
path = [ pkgs.curl pkgs.wget ];
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";
};
};
}