various
This commit is contained in:
parent
0f6a49366e
commit
024ea1168a
23 changed files with 485 additions and 101 deletions
|
@ -1,84 +0,0 @@
|
|||
{
|
||||
self,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
audiocomp = pkgs.writeShellApplication {
|
||||
name = "audiocomp";
|
||||
runtimeInputs = [
|
||||
pkgs.parallel
|
||||
pkgs.rsync
|
||||
pkgs.openssh
|
||||
];
|
||||
text = let
|
||||
remoteDir = self.nixosConfigurations.abacus.config.services.navidrome.settings.MusicFolder;
|
||||
enc = pkgs.writeShellApplication {
|
||||
name = "enc";
|
||||
runtimeInputs = [
|
||||
pkgs.opusTools
|
||||
];
|
||||
text = ''
|
||||
src=$1
|
||||
dst=$src
|
||||
dst=''${dst%.flac}.opus
|
||||
dst=/srv/compmusic/''${dst#/srv/music/}
|
||||
|
||||
if [[ -f "$dst" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
mkdir --parents -- "$(dirname -- "$dst")"
|
||||
|
||||
echo "encoding ''${src@Q} -> ''${dst@Q}" >&2
|
||||
exec opusenc --quiet --bitrate 96.000 -- "$src" "$dst"
|
||||
'';
|
||||
};
|
||||
clean = pkgs.writeShellApplication {
|
||||
name = "clean";
|
||||
text = ''
|
||||
del=$1
|
||||
chk=$del
|
||||
chk=''${chk%.opus}.flac
|
||||
chk=/srv/music/''${chk#/srv/compmusic/}
|
||||
|
||||
if [[ ! -f "$chk" ]]; then
|
||||
echo "deleting ''${del@Q}" >&2
|
||||
rm --force -- "$del"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in ''
|
||||
shopt -s globstar nullglob
|
||||
|
||||
find /srv/music -name '*.flac' -print0 | parallel --null -- ${lib.getExe enc} {}
|
||||
|
||||
find /srv/compmusic -name '*.flac' -exec ${clean} {} \;
|
||||
|
||||
echo syncing >&2
|
||||
rsync --verbose --verbose --archive --update --delete --mkpath --exclude lost+found \
|
||||
--rsh 'ssh -i /etc/ssh/ssh_host_ed25519_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' \
|
||||
-- /srv/compmusic/ root@wrz.one:${remoteDir}
|
||||
'';
|
||||
};
|
||||
in {
|
||||
systemd.services.audiocomp = {
|
||||
description = "Compress and sync music";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root";
|
||||
Group = "root";
|
||||
ExecStart = lib.getExe audiocomp;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.audiocomp = {
|
||||
description = "Compress and sync music daily";
|
||||
wantedBy = ["timers.target"];
|
||||
timerConfig = {
|
||||
OnCalendar = "*-*-* 03:00:00";
|
||||
Persistent = true;
|
||||
Unit = "audiocomp.service";
|
||||
};
|
||||
};
|
||||
}
|
51
hosts/server/vessel/musicomp.nix
Normal file
51
hosts/server/vessel/musicomp.nix
Normal file
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
self,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
services.musicomp.jobs.main = {
|
||||
music = "/srv/music";
|
||||
comp = "/srv/compmusic";
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
};
|
||||
inhibitsSleep = true;
|
||||
post = let
|
||||
remoteDir = self.nixosConfigurations.abacus.config.services.navidrome.settings.MusicFolder;
|
||||
rsyncExe = lib.getExe pkgs.rsync;
|
||||
in ''
|
||||
${rsyncExe} \
|
||||
--archive \
|
||||
--recursive \
|
||||
--delete \
|
||||
--update \
|
||||
--mkpath \
|
||||
--verbose --verbose \
|
||||
--exclude lost+found \
|
||||
--rsh 'ssh -i /etc/ssh/ssh_host_ed25519_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' \
|
||||
/srv/compmusic/ root@wrz.one:${remoteDir}
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.audiocomp = {
|
||||
description = "Compress and sync music";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root";
|
||||
Group = "root";
|
||||
ExecStart = lib.getExe audiocomp;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.audiocomp = {
|
||||
description = "Compress and sync music daily";
|
||||
wantedBy = ["timers.target"];
|
||||
timerConfig = {
|
||||
OnCalendar = "*-*-* 03:00:00";
|
||||
Persistent = true;
|
||||
Unit = "audiocomp.service";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue