2022-03-10 21:52:12 +01:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
pkgs,
|
|
|
|
|
lib,
|
|
|
|
|
...
|
|
|
|
|
}: let
|
2021-04-08 19:25:05 +02:00
|
|
|
firewall = (import <niveum/lib>).firewall lib;
|
|
|
|
|
|
2021-01-27 00:03:32 +01:00
|
|
|
streams = import <niveum/lib/streams.nix> {
|
|
|
|
|
di-fm-key = lib.strings.fileContents <secrets/di.fm/key>;
|
|
|
|
|
};
|
2021-01-27 08:22:03 +01:00
|
|
|
multi-room-audio-port = 8000;
|
2021-04-08 11:59:30 +02:00
|
|
|
password = lib.strings.fileContents <system-secrets/mpd-web.key>;
|
2022-03-10 21:52:12 +01:00
|
|
|
in {
|
2021-01-27 08:22:03 +01:00
|
|
|
imports = [
|
2021-06-28 08:23:25 +02:00
|
|
|
<niveum/modules/tuna.nix>
|
2021-01-27 08:22:03 +01:00
|
|
|
];
|
2020-10-28 21:43:33 +01:00
|
|
|
|
2022-03-10 21:52:12 +01:00
|
|
|
services.syncthing = let
|
|
|
|
|
mpd-directory = config.services.mpd.dataDir;
|
|
|
|
|
in {
|
2021-08-08 08:16:50 +02:00
|
|
|
enable = true;
|
2021-09-05 17:05:00 +02:00
|
|
|
user = config.services.mpd.user; # config.users.extraUsers.moodle.name;
|
|
|
|
|
openDefaultPorts = true;
|
|
|
|
|
configDir = "${mpd-directory}/.config/syncthing";
|
|
|
|
|
dataDir = "${mpd-directory}/.config/syncthing";
|
2021-12-01 09:47:14 +01:00
|
|
|
cert = toString <system-secrets/syncthing/cert.pem>;
|
|
|
|
|
key = toString <system-secrets/syncthing/key.pem>;
|
|
|
|
|
devices = {
|
|
|
|
|
inherit ((import <niveum/lib>).syncthing.devices) kabsa manakish heym;
|
|
|
|
|
};
|
|
|
|
|
folders.${config.services.mpd.musicDirectory} = {
|
2022-03-10 21:52:12 +01:00
|
|
|
devices = ["heym" "kabsa" "manakish"];
|
2021-12-01 09:47:14 +01:00
|
|
|
id = "music";
|
|
|
|
|
type = "receiveonly";
|
2021-08-08 08:16:50 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-27 08:22:03 +01:00
|
|
|
services.mpd = {
|
|
|
|
|
enable = true;
|
2021-04-08 11:59:30 +02:00
|
|
|
network.listenAddress = "0.0.0.0";
|
2021-01-27 08:22:03 +01:00
|
|
|
extraConfig = ''
|
|
|
|
|
log_level "default"
|
|
|
|
|
auto_update "yes"
|
|
|
|
|
|
|
|
|
|
audio_output {
|
2021-04-03 15:01:54 +02:00
|
|
|
type "pulse"
|
2021-01-27 08:22:03 +01:00
|
|
|
name "zaatar single room audio system"
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-10 21:52:12 +01:00
|
|
|
environment.systemPackages = [pkgs.mpc_cli];
|
2020-11-06 10:38:33 +01:00
|
|
|
|
2022-03-10 21:52:12 +01:00
|
|
|
networking.firewall = let
|
2021-04-08 19:25:05 +02:00
|
|
|
dport = config.services.mpd.network.port;
|
|
|
|
|
protocol = "tcp";
|
|
|
|
|
rules = [
|
2022-03-10 21:52:12 +01:00
|
|
|
(firewall.accept {
|
|
|
|
|
inherit dport protocol;
|
|
|
|
|
source = "192.168.0.0/16";
|
|
|
|
|
})
|
|
|
|
|
(firewall.accept {
|
|
|
|
|
inherit dport protocol;
|
|
|
|
|
source = "127.0.0.0/8";
|
|
|
|
|
})
|
2021-04-08 19:25:05 +02:00
|
|
|
];
|
|
|
|
|
in {
|
2022-03-10 21:52:12 +01:00
|
|
|
allowedTCPPorts = [80];
|
2021-04-08 19:25:05 +02:00
|
|
|
extraCommands = firewall.addRules rules;
|
|
|
|
|
extraStopCommands = firewall.removeRules rules;
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-10 21:52:12 +01:00
|
|
|
system.activationScripts.mpd-playlists = let
|
|
|
|
|
playlistFile = pkgs.writeText "radio.m3u" (lib.concatMapStringsSep "\n" (lib.getAttr "stream") streams);
|
2021-04-08 11:59:53 +02:00
|
|
|
in ''
|
|
|
|
|
rm -rf /var/lib/mpd/playlists
|
|
|
|
|
install -d /var/lib/mpd/playlists
|
|
|
|
|
ln -sfn "${toString playlistFile}" "/var/lib/mpd/playlists/radio.m3u"
|
|
|
|
|
'';
|
|
|
|
|
|
2021-06-28 08:23:25 +02:00
|
|
|
services.tuna = {
|
2021-01-26 23:05:16 +01:00
|
|
|
enable = true;
|
2021-06-28 08:23:25 +02:00
|
|
|
# stationsFile = "/etc/tuna/stations.json";
|
2022-03-10 21:52:12 +01:00
|
|
|
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;
|
2021-01-26 23:05:16 +01:00
|
|
|
webPort = 8080;
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-10 21:52:12 +01:00
|
|
|
systemd.services.tuna-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;
|
2021-04-07 09:37:57 +02:00
|
|
|
stationsJson = (pkgs.formats.json {}).generate "stations.json" stations;
|
2021-01-26 23:05:16 +01:00
|
|
|
in {
|
2022-01-28 12:50:23 +01:00
|
|
|
enable = false;
|
2022-03-10 21:52:12 +01:00
|
|
|
wantedBy = ["tuna.service"];
|
2021-01-26 23:05:16 +01:00
|
|
|
startAt = "hourly";
|
|
|
|
|
script = ''
|
2021-06-28 08:23:25 +02:00
|
|
|
mkdir -p /etc/tuna
|
2021-01-26 23:05:16 +01:00
|
|
|
antenne_asb_url=$(
|
|
|
|
|
${pkgs.curl}/bin/curl -sS 'https://www.caster.fm/widgets/em_player.php?jsinit=true&uid=529295&t=blue&c=' \
|
|
|
|
|
| grep streamUrl \
|
|
|
|
|
| sed ${lib.escapeShellArg "s/^.*'\\([^']*\\)'.*/\\1/"}
|
|
|
|
|
)
|
2021-06-28 08:23:25 +02:00
|
|
|
${pkgs.jq}/bin/jq "map(if .station == \"Antenne ASB\" then .stream |= \"$antenne_asb_url\" else . end)" < ${stationsJson} > /etc/tuna/stations.json
|
2021-01-26 23:05:16 +01:00
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.nginx = {
|
2021-01-27 08:22:03 +01:00
|
|
|
enable = true;
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
|
recommendedTlsSettings = true;
|
2021-09-19 11:41:36 +02:00
|
|
|
virtualHosts."radio.kmein.r" = {
|
2021-04-08 11:59:30 +02:00
|
|
|
basicAuth.dj = password;
|
2021-01-26 23:05:16 +01:00
|
|
|
locations."/" = {
|
2021-06-28 08:23:25 +02:00
|
|
|
proxyPass = "http://127.0.0.1:${toString config.services.tuna.webPort}";
|
2021-01-27 08:22:03 +01:00
|
|
|
proxyWebsockets = true;
|
2021-01-26 23:05:16 +01:00
|
|
|
};
|
2020-11-25 10:07:26 +01:00
|
|
|
};
|
|
|
|
|
};
|
2020-10-28 21:43:33 +01:00
|
|
|
}
|