owncast: add archiver

This commit is contained in:
Astro 2022-12-12 21:57:00 +01:00
parent 233498c9ae
commit 0906569551
2 changed files with 72 additions and 3 deletions

View File

@ -1,13 +1,17 @@
{ config, pkgs, ... }:
{
imports = [
./owncast-archiver.nix
];
deployment = {
vcpu = 8;
mem = 2048;
persistedShares = [ "/etc" "/home" "/var" ];
extraShares = [ {
source = "/glusterfs/big/microvms/c3d2/config/owncast/archive";
mountPoint = "/mnt/archive";
mountPoint = config.services.owncast-archiver.targetDir;
} ];
};
c3d2.hq.statistics.enable = true;
@ -38,7 +42,7 @@
proxyWebsockets = true;
};
locations."/archive/" = {
alias = "/mnt/archive/";
alias = "${config.services.owncast-archiver.targetDir}/";
extraConfig = ''
fancyindex on;
fancyindex_exact_size off;
@ -46,5 +50,9 @@
};
};
};
systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/mnt/archive" ];
systemd.services.nginx.serviceConfig.ReadWritePaths = [
config.services.owncast-archiver.targetDir
];
services.owncast-archiver.enable = true;
}

View File

@ -0,0 +1,61 @@
{ config, lib, pkgs, ... }:
let
owncastArchiver = with pkgs; writeScript "owncast-archiver.sh" ''
#! ${runtimeShell} -e
PATH=${lib.makeBinPath [ coreutils curl jq ffmpeg ]}
while true; do
STATUS="$(curl -s https://owncast.c3d2.de/api/status)"
ONLINE="$(echo "$STATUS" | jq -r .online)"
if [ "$ONLINE" = true ]; then
TITLE="$(echo "$STATUS" | jq -r .streamTitle)"
ffmpeg -i https://owncast.c3d2.de/hls/0/stream.m3u8 -c copy "$(echo "$(date -Iseconds)_$TITLE.mkv"|tr " +<>:/" "____\\-\\-")"
fi
sleep ${toString cfg.pollInterval}
done
'';
cfg = config.services.owncast-archiver;
in
{
options.services.owncast-archiver = with lib; {
enable = mkEnableOption "owncast archiver";
targetDir = mkOption {
type = types.str;
default = "/mnt/archive";
};
pollInterval = mkOption {
type = types.int;
default = 10;
};
};
config = lib.mkIf cfg.enable {
users.users.archiver = {
isSystemUser = true;
group = "nginx";
};
systemd.services.owncast-archiver = {
wantedBy = [ "multi-user.target" ];
after = [ "owncast.service" ];
serviceConfig = {
ReadWritePaths = cfg.targetDir;
WorkingDirectory = cfg.targetDir;
User = "archiver";
ExecStart = owncastArchiver;
Restart = "always";
RestartSec = 60;
};
};
};
}