mirror of
https://github.com/kmein/niveum
synced 2026-03-17 18:41:09 +01:00
feat(zaatar): stream mpd via http, proxy control panel and stream via nginx
This commit is contained in:
@@ -3,11 +3,39 @@ let
|
||||
streams = import <niveum/lib/streams.nix> {
|
||||
di-fm-key = lib.strings.fileContents <secrets/di.fm/key>;
|
||||
};
|
||||
multi-room-audio-port = 8000;
|
||||
in
|
||||
{
|
||||
imports = [ <niveum/modules/mpd-fm.nix> ];
|
||||
imports = [
|
||||
<niveum/modules/mpd-fm.nix>
|
||||
];
|
||||
|
||||
environment.systemPackages = [ pkgs.ncmpcpp pkgs.mpc_cli ];
|
||||
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 ];
|
||||
|
||||
services.mpd-fm = {
|
||||
enable = true;
|
||||
@@ -15,7 +43,7 @@ in
|
||||
webPort = 8080;
|
||||
};
|
||||
|
||||
systemd.services.antenne-asb =
|
||||
systemd.services.mpd-fm-stations =
|
||||
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);
|
||||
@@ -33,44 +61,22 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
services.mpd.enable = true;
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 80 ];
|
||||
services.nginx = {
|
||||
upstreams."mpd-fm-socket" = {
|
||||
extraConfig = ''
|
||||
server 127.0.0.1:${toString config.services.mpd-fm.webPort};
|
||||
'';
|
||||
};
|
||||
appendHttpConfig = ''
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
''' close;
|
||||
}
|
||||
'';
|
||||
enable = true;
|
||||
recommendedGzipSettings = true;
|
||||
recommendedOptimisation = true;
|
||||
recommendedProxySettings = true;
|
||||
recommendedTlsSettings = true;
|
||||
virtualHosts.default = {
|
||||
basicAuth.dj = lib.strings.fileContents <system-secrets/mpd-web.key>;
|
||||
locations."~ ^/listen" = {
|
||||
proxyPass = "http://127.0.0.1:${toString multi-room-audio-port}";
|
||||
};
|
||||
locations."/" = {
|
||||
proxyPass = "http://mpd-fm-socket";
|
||||
extraConfig = ''
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
''; # generate password hash with `openssl passwd -apr1`
|
||||
proxyPass = "http://127.0.0.1:${toString config.services.mpd-fm.webPort}";
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
# dont let anyone outside localhost or local network in
|
||||
networking.firewall.extraCommands =
|
||||
let
|
||||
mpd-fm-port = toString config.services.mpd-fm.webPort;
|
||||
in ''
|
||||
${pkgs.iptables}/bin/iptables -A INPUT -p tcp --dport ${mpd-fm-port} -s 192.168.0.0/16 -j ACCEPT
|
||||
${pkgs.iptables}/bin/iptables -A INPUT -p tcp --dport ${mpd-fm-port} -s 10.243.2.4 -j ACCEPT
|
||||
${pkgs.iptables}/bin/iptables -A INPUT -p tcp --dport ${mpd-fm-port} -s 127.0.0.0/8 -j ACCEPT
|
||||
${pkgs.iptables}/bin/iptables -A INPUT -p tcp --dport ${mpd-fm-port} -j DROP
|
||||
'';
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user