1
0
nixfiles/hosts/storage-2/mixcloud.nix

99 lines
2.8 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
mixcloudSources = {
avocadoom = "https://www.mixcloud.com/avocadoom/";
b4m = "https://www.mixcloud.com/b4m/";
barbnerdy = "https://soundcloud.com/barbnerdy";
beh2342 = "https://soundcloud.com/beh2342";
couchsofa = "https://www.mixcloud.com/couchsofa/";
#das-kraftfuttermischwerk = "https://soundcloud.com/das-kraftfuttermischwerk";
dj-spock = "https://www.mixcloud.com/dj_spock/";
LoungeControl = "https://www.mixcloud.com/LoungeControl/";
sh1bumi = "https://soundcloud.com/sh1bumi";
shroombab = "https://www.mixcloud.com/shroombab/";
tasmo = "https://www.mixcloud.com/tasmo/";
vidister = "https://mixcloud.com/vidister/";
};
generateYoutubedlMixcloudUnits = source: url: (
nameValuePair "youtube-dl-mixcloud-${source}" {
serviceConfig = {
User = "data-mixcloud";
Group = "data-mixcloud";
Restart="on-failure";
};
wants = [ "youtube-dl-prepare.service" ];
after = [ "youtube-dl-prepare.service" ];
path = [ pkgs.youtube-dl ];
script = ''
mkdir -p /data/mixcloud/${source}/
cd /data/mixcloud/${source}/
youtube-dl --ignore-errors --playlist-random --download-archive .already-downloaded.txt --newline -x --audio-format mp3 ${url}
'';
startAt = "*-*-* 05:05:00";
}
);
generateYoutubedlMixcloudTimers = source: url: (
nameValuePair "youtube-dl-mixcloud-${source}" {
timerConfig = {
RandomizedDelaySec = 10800;
};
}
);
in {
age.secrets.mixcloud-htpasswd = {
owner = "nginx";
group = "nginx";
};
services.nginx.virtualHosts = {
"mixcloud.clerie.de" = {
enableACME = true;
forceSSL = true;
locations."/" = {
alias = "/data/mixcloud/";
basicAuthFile = config.age.secrets.mixcloud-htpasswd.path;
extraConfig = ''
autoindex on;
autoindex_exact_size off;
'';
};
locations."/media/" = {
alias = "/data/media/";
basicAuthFile = config.age.secrets.mixcloud-htpasswd.path;
extraConfig = ''
autoindex on;
autoindex_exact_size off;
'';
};
};
};
users.users.data-mixcloud = {
group = "data-mixcloud";
home = "/data/mixcloud";
useDefaultShell = true;
isSystemUser = true;
};
users.groups.data-mixcloud = {};
systemd.services = {
"youtube-dl-prepare" = {
serviceConfig = {
Type = "oneshot";
RemainAfterExit = "true";
};
script = ''
mkdir -p /data/mixcloud
chown -R data-mixcloud:data-mixcloud /data/mixcloud
'';
};
} // (mapAttrs' generateYoutubedlMixcloudUnits mixcloudSources);
systemd.timers = (mapAttrs' generateYoutubedlMixcloudTimers mixcloudSources);
}