2022-12-24 17:16:39 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2023-09-21 05:06:27 +01:00
|
|
|
config,
|
2022-12-24 17:16:39 +00:00
|
|
|
...
|
|
|
|
}: let
|
2023-09-18 03:56:58 +01:00
|
|
|
inherit (lib.strings) concatStringsSep;
|
|
|
|
inherit (lib.lists) forEach;
|
2024-07-20 13:14:45 +01:00
|
|
|
inherit (lib.modules) mkMerge;
|
2023-09-18 03:56:58 +01:00
|
|
|
|
2024-07-20 13:11:15 +01:00
|
|
|
ports = {
|
|
|
|
mpd = 6600;
|
|
|
|
mpd-opus-low = 4242;
|
|
|
|
mpd-opus-medium = 4243;
|
|
|
|
mpd-opus-high = 4244;
|
|
|
|
mpd-flac = 4245;
|
|
|
|
};
|
|
|
|
|
2024-03-10 17:26:18 +00:00
|
|
|
inherit (config.services.secrets) secrets;
|
2022-12-24 17:16:39 +00:00
|
|
|
in {
|
2023-09-18 03:56:58 +01:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
mpc_cli
|
|
|
|
];
|
2022-12-24 17:16:39 +00:00
|
|
|
|
2024-06-14 21:15:15 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /Music - mpd mpd"
|
2024-05-25 21:10:26 +01:00
|
|
|
];
|
|
|
|
|
2024-05-25 21:31:19 +01:00
|
|
|
systemd.services.mpd = {
|
|
|
|
serviceConfig = {
|
2024-06-14 21:15:15 +01:00
|
|
|
ReadOnlyPaths = "/Music";
|
2024-05-25 21:31:19 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-24 17:16:39 +00:00
|
|
|
services.mpd = {
|
|
|
|
enable = true;
|
2024-09-10 19:44:31 +01:00
|
|
|
network.listenAddress = "any";
|
2024-06-14 21:15:15 +01:00
|
|
|
musicDirectory = "/Music";
|
2024-05-25 21:43:43 +01:00
|
|
|
dbFile = null;
|
2022-12-24 17:16:39 +00:00
|
|
|
credentials = [
|
|
|
|
{
|
|
|
|
passwordFile = "${secrets.mpd_control_password.path}";
|
|
|
|
permissions = ["read" "add" "control" "admin"];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
extraConfig =
|
|
|
|
''
|
2024-09-10 19:55:33 +01:00
|
|
|
bind_to_address "0.0.0.0"
|
2024-09-10 20:08:33 +01:00
|
|
|
#bind_to_address "::"
|
2022-12-24 17:16:39 +00:00
|
|
|
host_permissions "127.0.0.1 read,add,control,admin"
|
|
|
|
metadata_to_use "title,artist"
|
|
|
|
auto_update "yes"
|
|
|
|
audio_buffer_size "4096"
|
|
|
|
replaygain "track"
|
2024-02-08 17:47:36 +00:00
|
|
|
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"
|
|
|
|
}
|
2022-12-24 17:16:39 +00:00
|
|
|
''
|
2023-09-18 03:56:58 +01:00
|
|
|
+ concatStringsSep "\n" (forEach ["low" "medium" "high"] (quality: let
|
2022-12-24 17:16:39 +00:00
|
|
|
bitrates = {
|
|
|
|
"low" = "64";
|
|
|
|
"medium" = "96";
|
|
|
|
"high" = "128";
|
|
|
|
};
|
|
|
|
bitrate = bitrates.${quality};
|
|
|
|
in ''
|
|
|
|
audio_output {
|
2024-02-08 17:47:36 +00:00
|
|
|
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"
|
2022-12-24 17:16:39 +00:00
|
|
|
signal "music"
|
|
|
|
}
|
|
|
|
''))
|
|
|
|
+ ''
|
|
|
|
audio_output {
|
2024-02-08 17:47:36 +00:00
|
|
|
type "httpd"
|
|
|
|
name "http (flac) /flac"
|
|
|
|
encoder "flac"
|
|
|
|
port "${toString ports.mpd-flac}"
|
|
|
|
format "48000:24:2"
|
|
|
|
always_on "yes"
|
|
|
|
tags "yes"
|
2022-12-24 17:16:39 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2024-07-20 13:11:15 +01:00
|
|
|
|
|
|
|
services.nginx.virtualHosts."mpd.owo.monster" = let
|
|
|
|
extraConfig = ''
|
|
|
|
auth_basic "Music Password";
|
|
|
|
auth_basic_user_file ${secrets.music_stream_passwd.path};
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations = mkMerge [
|
|
|
|
{
|
|
|
|
"/flac" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString ports.mpd-flac}";
|
|
|
|
inherit extraConfig;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkMerge (forEach ["low" "medium" "high"] (quality: {
|
|
|
|
"/opus-${quality}" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString ports."mpd-opus-${quality}"}";
|
|
|
|
inherit extraConfig;
|
|
|
|
};
|
|
|
|
})))
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = with ports; [
|
|
|
|
mpd
|
|
|
|
];
|
2022-12-24 17:16:39 +00:00
|
|
|
}
|