nixfiles/hosts/hetzner-arm/containers/music/profiles/mpd.nix

126 lines
2.9 KiB
Nix
Raw Normal View History

{
lib,
pkgs,
config,
...
}: let
2023-09-18 03:56:58 +01:00
inherit (lib.strings) concatStringsSep;
inherit (lib.lists) forEach;
ports = import ../data/ports.nix;
2024-03-10 17:26:18 +00:00
inherit (config.services.secrets) secrets;
in {
2023-09-18 03:56:58 +01:00
environment.systemPackages = with pkgs; [
mpc_cli
];
systemd.tmpfiles.rules = [
"d /var/lib/mpd - mpd mpd"
"d /var/lib/mpd/state - mpd mpd"
2024-05-25 21:11:28 +01:00
"d /caches - root root"
"d /caches/music_serve - mpd mpd"
];
2024-05-25 21:31:19 +01:00
systemd.services.mpd = {
wants = ["rclone-serve-nfs-music.service"];
after = ["rclone-serve-nfs-music.service"];
serviceConfig = {
2024-05-26 10:14:32 +01:00
ProtectSystem = false;
2024-05-25 21:31:19 +01:00
};
};
services.mpd = {
enable = true;
network.listenAddress = "0.0.0.0";
musicDirectory = "nfs://127.0.0.1:2049/?version=3";
2024-05-25 21:43:43 +01:00
dbFile = null;
credentials = [
{
passwordFile = "${secrets.mpd_control_password.path}";
permissions = ["read" "add" "control" "admin"];
}
];
extraConfig =
''
host_permissions "127.0.0.1 read,add,control,admin"
metadata_to_use "title,artist"
auto_update "yes"
audio_buffer_size "4096"
replaygain "track"
audio_output_format "48000:24:2"
resampler {
plugin "soxr"
quality "very high"
threads "0"
}
2024-05-25 21:43:43 +01:00
database {
plugin "simple"
path "/var/lib/mpd/db"
}
''
2023-09-18 03:56:58 +01:00
+ concatStringsSep "\n" (forEach ["low" "medium" "high"] (quality: let
bitrates = {
"low" = "64";
"medium" = "96";
"high" = "128";
};
bitrate = bitrates.${quality};
in ''
audio_output {
type "httpd"
name "http (opus-${bitrate}k) /opus/${quality}"
encoder "opus"
port "${toString ports."mpd-opus-${quality}"}"
bitrate "${bitrate}000"
format "48000:24:2"
always_on "yes"
tags "yes"
signal "music"
}
''))
+ ''
audio_output {
type "httpd"
name "http (flac) /flac"
encoder "flac"
port "${toString ports.mpd-flac}"
format "48000:24:2"
always_on "yes"
tags "yes"
}
'';
};
services.rclone-serve = {
enable = true;
remotes = [
{
id = "main";
remote = "Music:";
type = "nfs";
user = "mpd";
serviceConfig = {
before = ["mpd.service"];
partOf = ["mpd.service"];
};
extraArgs = let
rcloneConfig = builtins.toFile "rclone.conf" ''
[Music]
type = webdav
url = https://storage-webdav.owo.monster/MusicRO/
vendor = other
'';
in [
"--addr=127.0.0.1:2049"
"--config=${rcloneConfig}"
"--cache-dir=/caches/music_serve"
"--vfs-cache-max-age=7d"
"--vfs-cache-max-size=4g"
"--vfs-cache-mode=full"
];
}
];
};
}