From 77dd5eee24ff9a56883ff39fd2a928f59bb02c10 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 21 May 2016 13:47:09 +0200 Subject: l 2: add radio.nix --- lass/2configs/radio.nix | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 lass/2configs/radio.nix (limited to 'lass/2configs/radio.nix') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix new file mode 100644 index 00000000..8cc2a2be --- /dev/null +++ b/lass/2configs/radio.nix @@ -0,0 +1,133 @@ +{ config, pkgs, ... }: +let + name = "radio"; + mainUser = config.users.extraUsers.mainUser; + inherit (config.krebs.lib) genid; + + admin-password = import ; + source-password = import ; + +in { + users.users = { + "${name}" = rec { + inherit name; + group = name; + uid = genid name; + description = "radio manager"; + home = "/home/${name}"; + useDefaultShell = true; + createHome = true; + openssh.authorizedKeys.keys = [ + config.krebs.users.lass.pubkey + ]; + }; + }; + + users.groups = { + "radio" = {}; + }; + + krebs.per-user.${name}.packages = with pkgs; [ + ncmpcpp + mpc_cli + tmux + ]; + + security.sudo.extraConfig = '' + ${mainUser.name} ALL=(${name}) NOPASSWD: ALL + ''; + + services.mpd = { + enable = true; + group = "radio"; + musicDirectory = "/home/radio/the_playlist/music"; + extraConfig = '' + audio_output { + type "shout" + encoding "ogg" + name "my cool stream" + host "localhost" + port "8000" + mount "/radio.ogg" + + # This is the source password in icecast.xml + password "${source-password}" + + # Set either quality or bit rate + # quality "5.0" + bitrate "128" + + format "44100:16:1" + + # Optional Parameters + user "source" + # description "here is my long description" + # genre "jazz" + } # end of audio_output + + ''; + }; + + services.icecast = { + enable = true; + hostname = "config.krebs.build.host.name"; + admin.password = admin-password; + extraConf = '' + + ${source-password} + + ''; + }; + + krebs.iptables = { + tables = { + filter.INPUT.rules = [ + { predicate = "-p tcp --dport 8000"; target = "ACCEPT"; } + ]; + }; + }; + + systemd.timers.radio = { + description = "radio autoadder timer"; + wantedBy = [ "timers.target" ]; + + timerConfig = { + OnCalendar = "*:*"; + }; + }; + + systemd.services.radio = let + autoAdd = pkgs.writeDash "autoAdd" '' + LIMIT=$1 #in secconds + + addRandom () { + mpc add "$(mpc ls | shuf -n1)" + } + + timeLeft () { + playlistDuration=$(mpc --format '%time%' playlist | awk -F ':' 'BEGIN{t=0} {t+=$1*60+$2} END{print t}') + currentTime=$(mpc status | awk '/^\[playing\]/ { sub(/\/.+/,"",$3); split($3,a,/:/); print a[1]*60+a[2] }') + expr ''${playlistDuration:-0} - ''${currentTime:-0} + } + + if test $(timeLeft) -le $LIMIT; then + addRandom + fi + ''; + in { + description = "radio playlist autoadder"; + after = [ "network.target" ]; + + path = with pkgs; [ + gawk + mpc_cli + ]; + + restartIfChanged = true; + + serviceConfig = { + Restart = "always"; + ExecStart = "${autoAdd} 100"; + }; + }; +} -- cgit v1.2.3 From db98837af5aef7687b12ca7a8ab336a7ed2b80ed Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 25 May 2016 16:22:48 +0200 Subject: l 2 radio: add and use utils --- lass/2configs/radio.nix | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lass/2configs/radio.nix') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 8cc2a2be..518ab8fa 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -1,4 +1,7 @@ { config, pkgs, ... }: + +with config.krebs.lib; + let name = "radio"; mainUser = config.users.extraUsers.mainUser; @@ -7,6 +10,20 @@ let admin-password = import ; source-password = import ; + add_random = pkgs.writeDashBin "add_random" '' + mpc add "$(mpc ls | shuf -n1)" + ''; + + skip_track = pkgs.writeDashBin "skip_track" '' + ${add_random}/bin/add_random + echo skipping: "$(${print_current}/bin/print_current)" + ${pkgs.mpc_cli}/bin/mpc -q next + ''; + + print_current = pkgs.writeDashBin "print_current" '' + ${pkgs.mpc_cli}/bin/mpc current -f %file% + ''; + in { users.users = { "${name}" = rec { @@ -28,6 +45,9 @@ in { }; krebs.per-user.${name}.packages = with pkgs; [ + add_random + skip_track + print_current ncmpcpp mpc_cli tmux @@ -100,10 +120,6 @@ in { autoAdd = pkgs.writeDash "autoAdd" '' LIMIT=$1 #in secconds - addRandom () { - mpc add "$(mpc ls | shuf -n1)" - } - timeLeft () { playlistDuration=$(mpc --format '%time%' playlist | awk -F ':' 'BEGIN{t=0} {t+=$1*60+$2} END{print t}') currentTime=$(mpc status | awk '/^\[playing\]/ { sub(/\/.+/,"",$3); split($3,a,/:/); print a[1]*60+a[2] }') @@ -111,7 +127,7 @@ in { } if test $(timeLeft) -le $LIMIT; then - addRandom + ${add_random}/bin/add_random fi ''; in { -- cgit v1.2.3 From 9a8cfe0c2183242d53207e597e9bbb3a7ba91b0b Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 25 May 2016 16:24:38 +0200 Subject: l 2 radio: add Reaktor config --- lass/2configs/radio.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lass/2configs/radio.nix') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 518ab8fa..99a8c085 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -146,4 +146,23 @@ in { ExecStart = "${autoAdd} 100"; }; }; + + krebs.Reaktor = { + enable = true; + nickname = "the_playlist|r"; + channels = [ "#the_playlist" ]; + extraEnviron = { + REAKTOR_HOST = "irc.freenode.org"; + }; + plugins = with pkgs.ReaktorPlugins; [ + (buildSimpleReaktorPlugin "skip" { + script = "${skip_track}/bin/skip_track"; + pattern = "^skip$"; + }) + (buildSimpleReaktorPlugin "current" { + script = "${print_current}/bin/print_current"; + pattern = "^current$"; + }) + ]; + }; } -- cgit v1.2.3 From e7f114ae090d6d2d0b9f11f03f58797feaef016a Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 25 May 2016 16:25:06 +0200 Subject: l 2 radio: add config for lassul.us/the_playlist --- lass/2configs/radio.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lass/2configs/radio.nix') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 99a8c085..2d1596e3 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -165,4 +165,29 @@ in { }) ]; }; + krebs.nginx.servers."lassul.us".locations = let + html = pkgs.writeText "index.html" '' + + + + + lassulus playlist + + +
+ +
+
+ +
+ + + + ''; + in [ + (nameValuePair "/the_playlist" '' + default_type "text/html"; + alias ${html}; + '') + ]; } -- cgit v1.2.3 From 39be633cf42aaaa4f8a6a992fd3af4e139ab8917 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 25 May 2016 20:57:08 +0200 Subject: l 2 radio print_current: show youtube link --- lass/2configs/radio.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lass/2configs/radio.nix') diff --git a/lass/2configs/radio.nix b/lass/2configs/radio.nix index 2d1596e3..17be327b 100644 --- a/lass/2configs/radio.nix +++ b/lass/2configs/radio.nix @@ -21,7 +21,9 @@ let ''; print_current = pkgs.writeDashBin "print_current" '' - ${pkgs.mpc_cli}/bin/mpc current -f %file% + echo "$(${pkgs.mpc_cli}/bin/mpc current -f %file%) \ + $(${pkgs.mpc_cli}/bin/mpc current -f %file% \ + | ${pkgs.gnused}/bin/sed 's@.*\(.\{11\}\)\.ogg@http://www.youtube.com/watch?v=\1@')" ''; in { -- cgit v1.2.3