storage-ng: add streamdump

This commit is contained in:
Astro 2022-03-09 21:19:26 +01:00
parent f23e2ac2d2
commit 0608a20f46
2 changed files with 47 additions and 1 deletions

View File

@ -1,4 +1,4 @@
{ config, pkgs, lib, strings, ... }:
{ hostRegistry, config, pkgs, lib, strings, ... }:
let
eth0 = "ens18";
@ -7,6 +7,7 @@ in
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
./streamdump.nix
# ../../config
# ../../config/hq.nix
# ../../config/shared.nix
@ -48,6 +49,11 @@ in
defaultGateway.address = "172.22.99.4";
defaultGateway.interface = eth0;
nameservers = [
hostRegistry.hosts.dnscache.ip4
hostRegistry.hosts.dnscache.ip6
"9.9.9.9"
];
};
environment.systemPackages = with pkgs; [

View File

@ -0,0 +1,40 @@
{ config, pkgs, ... }:
let
archiveRoot = "/mnt/cephfs/c3d2/Radio";
streams = {
coloradio = "http://streaming.fueralle.org/coloradio_160.mp3";
};
in {
systemd.services = builtins.foldl' (result: stream:
let
url = streams.${stream};
in result // {
"streamdump-${stream}" = {
description = "Stream archive for ${stream}";
wantedBy = [ "multi-user.target" ];
path = with pkgs; [
wget
mp3splt
];
script = ''
DIR=${archiveRoot}/${stream}/$(date +%F)
mkdir -p $DIR
cd $DIR
NAME=${stream}-$(date +%T)
set +e
wget --quiet -O $NAME.mp3 "${url}"
set -e
mp3splt -s -p th=-44,min=2 -o "@f-@N" $NAME.mp3
rm $NAME.mp3
'';
serviceConfig = {
User = "k-ot";
Group = config.users.users.k-ot.group;
Restart = "always";
RestartSec = "5sec";
};
};
}
) {} (builtins.attrNames streams);
}