From ea57f539b038ebafdb46eea55db16d505d894c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 27 Jan 2021 08:22:03 +0100 Subject: [PATCH] feat(zaatar): stream mpd via http, proxy control panel and stream via nginx --- configs/mpd.nix | 78 ++++++++++++++++++++----------------- lib/streams.nix | 40 ++++++++++++++++++- packages/MPD.FM/default.nix | 4 +- 3 files changed, 83 insertions(+), 39 deletions(-) diff --git a/configs/mpd.nix b/configs/mpd.nix index f41227a..b5bca02 100644 --- a/configs/mpd.nix +++ b/configs/mpd.nix @@ -3,11 +3,39 @@ let streams = import { di-fm-key = lib.strings.fileContents ; }; + multi-room-audio-port = 8000; in { - imports = [ ]; + imports = [ + + ]; - 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 ; + 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 - ''; - */ } diff --git a/lib/streams.nix b/lib/streams.nix index 2c82dfb..53e4173 100644 --- a/lib/streams.nix +++ b/lib/streams.nix @@ -23,6 +23,9 @@ let radiosai-name = name: "${name} | Radiosai"; radiosai = name: "https://stream.sssmediacentre.org/${name}"; + royal-name = name: "${name} | RoyalRadio"; + royal = name: "http://193.33.170.218:8000/${name}"; + caster-fm = subdomain: port: "http://${subdomain}.caster.fm:${toString port}/listen.mp3?authn0b0236758bd0e178156d0787327a055d"; in [ { @@ -1001,7 +1004,7 @@ in [ } { station = rautemusik-name "Wacken Radio"; - desc = "Metal, Heavy MetaL"; + desc = "Metal, Heavy Metal"; stream = rautemusik "wackenradio"; } { @@ -1303,6 +1306,41 @@ in [ stream = radiosai "ameri"; desc = "The voice of pure love."; } + { + stream = royal "RoyalPopsa"; + station = royal-name "Popsa"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyalTrance"; + station = royal-name "Trance"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyalDrum"; + station = royal-name "Drum"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyalTrap"; + station = royal-name "Trap"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyalRock"; + station = royal-name "Rock"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyalLounge"; + station = royal-name "Lounge"; + desc = "из Санкт-Петербурга"; + } + { + stream = royal "RoyaLove"; + station = royal-name "Love"; + desc = "из Санкт-Петербурга"; + } ] /* (caster-fm "TODO" "noasrv" 10182) # https://github.com/cccruzr/albumsyoumusthear/blob/7e00baf575e4d357cd275d54d1aeb717321141a8/HLS/IBERO_90_1.m3u diff --git a/packages/MPD.FM/default.nix b/packages/MPD.FM/default.nix index b97c4fd..9c85e6d 100644 --- a/packages/MPD.FM/default.nix +++ b/packages/MPD.FM/default.nix @@ -4,8 +4,8 @@ mkYarnPackage rec { src = fetchFromGitHub { owner = "kmein"; repo = "MPD.FM"; - rev = "c7cbaa4ce3b350f26cad54378db22c8ec58d987b"; - sha256 = "1iklzbaji7ls01jfi1r0frhjq2i1w29kmar7vgw32f5mgj19cyvd"; + rev = "5f309c2579a9cbbbc4f7eb6a2e2f3993cc177630"; + sha256 = "0ladh96s656i7yd9qxrpqq4x513r88zas7112rqn5sgxxaccbh72"; }; packageJSON = "${src}/package.json"; yarnLock = ./yarn.lock;