l: move radio to subfolder

This commit is contained in:
lassulus 2022-05-18 16:57:57 +02:00
parent d091706730
commit 5cbb9aeb72
3 changed files with 64 additions and 32 deletions

View File

@ -113,8 +113,7 @@ with import <stockholm/lib>;
} }
<stockholm/lass/2configs/exim-smarthost.nix> <stockholm/lass/2configs/exim-smarthost.nix>
<stockholm/lass/2configs/privoxy-retiolum.nix> <stockholm/lass/2configs/privoxy-retiolum.nix>
<stockholm/lass/2configs/radio.nix> <stockholm/lass/2configs/radio>
<stockholm/lass/2configs/radio-news.nix>
<stockholm/lass/2configs/binary-cache/server.nix> <stockholm/lass/2configs/binary-cache/server.nix>
<stockholm/lass/2configs/iodined.nix> <stockholm/lass/2configs/iodined.nix>
<stockholm/lass/2configs/paste.nix> <stockholm/lass/2configs/paste.nix>

View File

@ -105,6 +105,10 @@ let
''; '';
in { in {
imports = [
./news.nix
];
users.users = { users.users = {
"${name}" = rec { "${name}" = rec {
inherit name; inherit name;
@ -161,14 +165,14 @@ in {
output.icecast(mount = '/music.ogg', password = 'hackme', %vorbis(quality = 1), source) output.icecast(mount = '/music.ogg', password = 'hackme', %vorbis(quality = 1), source)
output.icecast(mount = '/music.mp3', password = 'hackme', %mp3.vbr(), source) output.icecast(mount = '/music.mp3', password = 'hackme', %mp3.vbr(), source)
output.icecast(mount = '/music.opus', password = 'hackme', %opus(), source) output.icecast(mount = '/music.opus', password = 'hackme', %opus(bitrate = 64), source)
extra_input = audio_to_stereo(input.harbor("live", port=1338)) extra_input = audio_to_stereo(input.harbor("live", port=1338))
o = smooth_add(normal = source, special = extra_input) o = smooth_add(normal = source, special = extra_input)
output.icecast(mount = '/radio.ogg', password = 'hackme', %vorbis(quality = 1), o) output.icecast(mount = '/radio.ogg', password = 'hackme', %vorbis(quality = 1), o)
output.icecast(mount = '/radio.mp3', password = 'hackme', %mp3.vbr(), o) output.icecast(mount = '/radio.mp3', password = 'hackme', %mp3.vbr(), o)
output.icecast(mount = '/radio.opus', password = 'hackme', %opus(), o) output.icecast(mount = '/radio.opus', password = 'hackme', %opus(bitrate = 64), o)
''; '';
services.icecast = { services.icecast = {
enable = true; enable = true;
@ -227,7 +231,7 @@ in {
systemd.services.radio-recent = let systemd.services.radio-recent = let
recentlyPlayed = pkgs.writeDash "recentlyPlayed" '' recentlyPlayed = pkgs.writeDash "recentlyPlayed" ''
set -xeu set -xefu
LIMIT=1000 #how many tracks to keep in the history LIMIT=1000 #how many tracks to keep in the history
HISTORY_FILE=/var/lib/radio/recent HISTORY_FILE=/var/lib/radio/recent
while :; do while :; do
@ -368,6 +372,16 @@ in {
locations."= /good".extraConfig = '' locations."= /good".extraConfig = ''
proxy_pass http://localhost:8001; proxy_pass http://localhost:8001;
''; '';
locations."= /radio.sh".extraConfig = ''
alias ${pkgs.writeScript "radio.sh" ''
#!/bin/sh
while sleep 1; do
mpv \
--cache-secs=0 --demuxer-readahead-secs=0 --untimed --cache-pause=no \
'http://lassul.us:8000/radio.opus'
done
''};
'';
locations."= /controls".extraConfig = '' locations."= /controls".extraConfig = ''
default_type "text/html"; default_type "text/html";
alias ${pkgs.writeText "controls.html" '' alias ${pkgs.writeText "controls.html" ''
@ -482,11 +496,9 @@ in {
}; };
services.syncthing.declarative.folders."the_playlist" = { services.syncthing.declarative.folders."the_playlist" = {
path = "/home/radio/music/the_playlist"; path = "/home/radio/music/the_playlist";
devices = [ "mors" "phone" "prism" ]; devices = [ "mors" "phone" "prism" "omo" ];
};
krebs.permown."/home/radio/music/the_playlist" = {
owner = "radio";
group = "syncthing";
umask = "0002";
}; };
krebs.acl."/home/radio/music/the_playlist"."u:syncthing:X".parents = true;
krebs.acl."/home/radio/music/the_playlist"."u:syncthing:rwX" = {};
krebs.acl."/home/radio/music/the_playlist"."u:radio:rwX" = {};
} }

View File

@ -2,11 +2,26 @@
let let
weather_report = pkgs.writers.writeDashBin "weather_report" '' weather_report = pkgs.writers.writeDashBin "weather_report" ''
set -efu set -efu
${pkgs.curl}/bin/curl -fsSL https://wttr.in/''${1-}?format=j1 \ export PATH="${lib.makeBinPath [
| ${pkgs.jq}/bin/jq -r ' pkgs.iproute2
[.nearest_area[0] | "Weather report for \(.areaName[0].value), \(.country[0].value)."] pkgs.coreutils
+ [.current_condition[0] | "Currently it is \(.weatherDesc[0].value) outside with a temperature of \(.temp_C) degrees."] pkgs.jq
| join("\n") pkgs.curl
pkgs.gnugrep
pkgs.gnused
]}"
ss -Hno state established 'sport = :8000' |
grep '^tcp' | sed 's/.*\[.*\].*\[\(::ffff:\)\{0,1\}\(.*\)\].*/\2/' |
sed '/127.0.0.1/d;/:/d' |
while read -r ip; do
curl -sSL "https://wttr.in/@$ip?format=j1"
done | jq -rs 'unique_by(.nearest_area[0].areaName[0].value) |
map((.nearest_area[0] |
"Weather report for \(.areaName[0].value), \(.country[0].value).")
+ (.current_condition[0] |
" Currently it is \(.weatherDesc[0].value) outside with a temperature of \(.temp_C) degrees."
)
) | unique | .[]'
' '
''; '';
send_to_radio = pkgs.writers.writeDashBin "send_to_radio" '' send_to_radio = pkgs.writers.writeDashBin "send_to_radio" ''
@ -26,17 +41,15 @@ let
''; '';
newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ '' newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ ''
echo " cat << EOF
hello crabpeople! hello crabpeople!
$(${pkgs.ddate}/bin/ddate | sed 's/YOLD/Year of Discord/')! $(${pkgs.ddate}/bin/ddate +'Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H')
It is $(date --utc +%H) o clock UTC. It is $(date --utc +%H) o clock UTC.
todays news: todays news:
$(get_current_news) $(get_current_news)
$(gc_news) $(gc_news)
$(weather_report berlin) $(weather_report)
$(weather_report 70173) EOF
$(weather_report munich)
"
''; '';
in in
{ {
@ -73,15 +86,23 @@ in
}; };
script = ''. ${pkgs.writers.writeDash "htgen-news" '' script = ''. ${pkgs.writers.writeDash "htgen-news" ''
set -xefu set -xefu
case "$Method $Request_URI" in case "''${Method:-GET} $Request_URI" in
"POST /") "GET /")
payload=$(head -c "$req_content_length" \
| sed 's/+/ /g;s/%\(..\)/\\x\1/g;' \
| xargs -0 echo -e \
)
echo "$payload" | jq 'has("from") and has("to") and has("text")' >&2
echo "$payload" | jq -c '{ from: (.from | fromdate | todate), to: (.to | fromdate | todate), text: .text }' >> $HOME/news
printf 'HTTP/1.1 200 OK\r\n' printf 'HTTP/1.1 200 OK\r\n'
printf 'Access-Control-Allow-Origin: *\r\n';
printf 'Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n';
printf 'Connection: close\r\n'
printf '\r\n'
cat "$HOME"/news | jq -sc .
exit
;;
"POST /")
payload=$(head -c "$req_content_length")
echo "$payload" | jq 'has("from") and has("to") and has("text")' >&2
echo "$payload" | jq -c '{ from: (.from | fromdate | todate), to: (.to | fromdate | todate), text: .text }' >> "$HOME"/news
printf 'HTTP/1.1 200 OK\r\n'
printf 'Access-Control-Allow-Origin: *\r\n';
printf 'Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n';
printf 'Connection: close\r\n' printf 'Connection: close\r\n'
printf '\r\n' printf '\r\n'
exit exit