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/privoxy-retiolum.nix>
<stockholm/lass/2configs/radio.nix>
<stockholm/lass/2configs/radio-news.nix>
<stockholm/lass/2configs/radio>
<stockholm/lass/2configs/binary-cache/server.nix>
<stockholm/lass/2configs/iodined.nix>
<stockholm/lass/2configs/paste.nix>

View File

@ -105,6 +105,10 @@ let
'';
in {
imports = [
./news.nix
];
users.users = {
"${name}" = rec {
inherit name;
@ -161,14 +165,14 @@ in {
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.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))
o = smooth_add(normal = source, special = extra_input)
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.opus', password = 'hackme', %opus(), o)
output.icecast(mount = '/radio.opus', password = 'hackme', %opus(bitrate = 64), o)
'';
services.icecast = {
enable = true;
@ -227,7 +231,7 @@ in {
systemd.services.radio-recent = let
recentlyPlayed = pkgs.writeDash "recentlyPlayed" ''
set -xeu
set -xefu
LIMIT=1000 #how many tracks to keep in the history
HISTORY_FILE=/var/lib/radio/recent
while :; do
@ -368,6 +372,16 @@ in {
locations."= /good".extraConfig = ''
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 = ''
default_type "text/html";
alias ${pkgs.writeText "controls.html" ''
@ -482,11 +496,9 @@ in {
};
services.syncthing.declarative.folders."the_playlist" = {
path = "/home/radio/music/the_playlist";
devices = [ "mors" "phone" "prism" ];
};
krebs.permown."/home/radio/music/the_playlist" = {
owner = "radio";
group = "syncthing";
umask = "0002";
devices = [ "mors" "phone" "prism" "omo" ];
};
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

@ -1,13 +1,28 @@
{ config, lib, pkgs, ... }:
let
weather_report = pkgs.writers.writeDashBin "weather_report" ''
set -efu
${pkgs.curl}/bin/curl -fsSL https://wttr.in/''${1-}?format=j1 \
| ${pkgs.jq}/bin/jq -r '
[.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."]
| join("\n")
'
set -efu
export PATH="${lib.makeBinPath [
pkgs.iproute2
pkgs.coreutils
pkgs.jq
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" ''
${pkgs.vorbisTools}/bin/oggenc - |
@ -26,17 +41,15 @@ let
'';
newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ ''
echo "
cat << EOF
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.
todays news:
$(get_current_news)
$(gc_news)
$(weather_report berlin)
$(weather_report 70173)
$(weather_report munich)
"
$(weather_report)
EOF
'';
in
{
@ -73,15 +86,23 @@ in
};
script = ''. ${pkgs.writers.writeDash "htgen-news" ''
set -xefu
case "$Method $Request_URI" in
"POST /")
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
case "''${Method:-GET} $Request_URI" in
"GET /")
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 '\r\n'
exit