2020-10-28 21:43:33 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
let
|
2021-01-27 00:03:32 +01:00
|
|
|
streams = import <niveum/lib/streams.nix> {
|
|
|
|
|
di-fm-key = lib.strings.fileContents <secrets/di.fm/key>;
|
|
|
|
|
};
|
2021-01-27 08:22:03 +01:00
|
|
|
multi-room-audio-port = 8000;
|
2020-10-28 21:43:33 +01:00
|
|
|
in
|
|
|
|
|
{
|
2021-01-27 08:22:03 +01:00
|
|
|
imports = [
|
|
|
|
|
<niveum/modules/mpd-fm.nix>
|
|
|
|
|
];
|
2020-10-28 21:43:33 +01:00
|
|
|
|
2021-01-27 08:22:03 +01:00
|
|
|
services.mpd = {
|
|
|
|
|
enable = true;
|
|
|
|
|
extraConfig = ''
|
|
|
|
|
log_level "default"
|
|
|
|
|
auto_update "yes"
|
|
|
|
|
|
|
|
|
|
audio_output {
|
|
|
|
|
type "alsa"
|
|
|
|
|
name "zaatar single room audio system"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audio_output {
|
|
|
|
|
type "httpd"
|
|
|
|
|
name "zaatar multi room audio system"
|
|
|
|
|
encoder "vorbis" # optional
|
|
|
|
|
port "${toString multi-room-audio-port}"
|
|
|
|
|
quality "5.0" # do not define if bitrate is defined
|
|
|
|
|
# bitrate "128" # do not define if quality is defined
|
|
|
|
|
format "44100:16:2"
|
|
|
|
|
always_on "yes" # prevent MPD from disconnecting all listeners when playback is stopped.
|
|
|
|
|
tags "yes" # httpd supports sending tags to listening streams.
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.mpc_cli ];
|
2020-11-06 10:38:33 +01:00
|
|
|
|
2021-01-26 23:05:16 +01:00
|
|
|
services.mpd-fm = {
|
|
|
|
|
enable = true;
|
|
|
|
|
stationsFile = "/etc/mpd-fm/stations.json";
|
|
|
|
|
webPort = 8080;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-27 08:22:03 +01:00
|
|
|
systemd.services.mpd-fm-stations =
|
2021-01-26 23:05:16 +01:00
|
|
|
let
|
|
|
|
|
stations = lib.lists.imap0 (id: {desc ? "", logo ? "https://picsum.photos/seed/${builtins.hashString "md5" stream}/300", stream, station}: { inherit id desc logo stream station; }) streams;
|
|
|
|
|
stationsJson = pkgs.writeText "stations.json" (builtins.toJSON stations);
|
|
|
|
|
in {
|
|
|
|
|
wantedBy = [ "mpd-fm.service" ];
|
|
|
|
|
startAt = "hourly";
|
|
|
|
|
script = ''
|
|
|
|
|
mkdir -p /etc/mpd-fm
|
|
|
|
|
antenne_asb_url=$(
|
|
|
|
|
${pkgs.curl}/bin/curl -sS 'https://www.caster.fm/widgets/em_player.php?jsinit=true&uid=529295&t=blue&c=' \
|
|
|
|
|
| grep streamUrl \
|
|
|
|
|
| sed ${lib.escapeShellArg "s/^.*'\\([^']*\\)'.*/\\1/"}
|
|
|
|
|
)
|
|
|
|
|
${pkgs.jq}/bin/jq "map(if .station == \"Antenne ASB\" then .stream |= \"$antenne_asb_url\" else . end)" < ${stationsJson} > /etc/mpd-fm/stations.json
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-27 08:22:03 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
2021-01-26 23:05:16 +01:00
|
|
|
services.nginx = {
|
2021-01-27 08:22:03 +01:00
|
|
|
enable = true;
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
|
recommendedTlsSettings = true;
|
2021-01-26 23:05:16 +01:00
|
|
|
virtualHosts.default = {
|
|
|
|
|
basicAuth.dj = lib.strings.fileContents <system-secrets/mpd-web.key>;
|
2021-01-27 08:22:03 +01:00
|
|
|
locations."~ ^/listen" = {
|
|
|
|
|
proxyPass = "http://127.0.0.1:${toString multi-room-audio-port}";
|
|
|
|
|
};
|
2021-01-26 23:05:16 +01:00
|
|
|
locations."/" = {
|
2021-01-27 08:22:03 +01:00
|
|
|
proxyPass = "http://127.0.0.1:${toString config.services.mpd-fm.webPort}";
|
|
|
|
|
proxyWebsockets = true;
|
2021-01-26 23:05:16 +01:00
|
|
|
};
|
2020-11-25 10:07:26 +01:00
|
|
|
};
|
|
|
|
|
};
|
2020-10-28 21:43:33 +01:00
|
|
|
}
|