summaryrefslogtreecommitdiffstats
path: root/lass
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-05-18 16:57:57 +0200
committerlassulus <lassulus@lassul.us>2022-05-18 16:58:55 +0200
commit5cbb9aeb7249c51e7a6f4075695e0ca1ec9e0296 (patch)
treecbe1717dc179330983736c620732760e2034931f /lass
parentd091706730b98b3a6c9a85f76eea81cae04e8e0b (diff)
l: move radio to subfolder
Diffstat (limited to 'lass')
-rw-r--r--lass/1systems/prism/config.nix3
-rw-r--r--lass/2configs/radio/default.nix (renamed from lass/2configs/radio.nix)30
-rw-r--r--lass/2configs/radio/news.nix (renamed from lass/2configs/radio-news.nix)59
3 files changed, 62 insertions, 30 deletions
diff --git a/lass/1systems/prism/config.nix b/lass/1systems/prism/config.nix
index c62091428..d174e6057 100644
--- a/lass/1systems/prism/config.nix
+++ b/lass/1systems/prism/config.nix
@@ -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>
diff --git a/lass/2configs/radio.nix b/lass/2configs/radio/default.nix
index 15d07dada..34115f56a 100644
--- a/lass/2configs/radio.nix
+++ b/lass/2configs/radio/default.nix
@@ -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" = {};
}
diff --git a/lass/2configs/radio-news.nix b/lass/2configs/radio/news.nix
index eb7d3bd9a..4f88197cb 100644
--- a/lass/2configs/radio-news.nix
+++ b/lass/2configs/radio/news.nix
@@ -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
+ 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" \
- | sed 's/+/ /g;s/%\(..\)/\\x\1/g;' \
- | xargs -0 echo -e \
- )
+ 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
+ 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