2022-03-10 21:52:12 +01:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
pkgs,
|
|
|
|
|
lib,
|
|
|
|
|
...
|
|
|
|
|
}: let
|
2023-07-13 22:13:22 +02:00
|
|
|
mukkeMountPoint = "/mnt/mukke";
|
2024-04-08 08:17:52 +02:00
|
|
|
fritzboxMountPoint = "/mnt/fritz";
|
2023-07-13 22:13:22 +02:00
|
|
|
|
2023-02-22 10:02:55 +01:00
|
|
|
streams = import ../../lib/streams.nix {
|
2023-07-25 16:19:21 +02:00
|
|
|
di-fm-key = "%DI_FM_KEY%"; # TODO lib.strings.fileContents <secrets/di.fm/key>;
|
2021-01-27 00:03:32 +01:00
|
|
|
};
|
2022-03-10 21:52:12 +01:00
|
|
|
in {
|
2024-01-08 14:55:38 +01:00
|
|
|
users.users.${config.services.mpd.user}.extraGroups = ["pipewire" "audio"];
|
2024-01-02 10:35:03 +01: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 {
|
2024-01-02 10:35:03 +01:00
|
|
|
type "pipewire"
|
2021-01-27 08:22:03 +01:00
|
|
|
name "zaatar single room audio system"
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-13 22:13:22 +02:00
|
|
|
fileSystems.${mukkeMountPoint} = {
|
|
|
|
|
device = "//mukke.r/public";
|
|
|
|
|
fsType = "cifs";
|
|
|
|
|
options = [
|
|
|
|
|
"guest"
|
|
|
|
|
"nofail"
|
|
|
|
|
"noauto"
|
|
|
|
|
"ro"
|
|
|
|
|
"rsize=16777216"
|
|
|
|
|
"cache=loose"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 08:17:52 +02:00
|
|
|
fileSystems."${fritzboxMountPoint}" = {
|
|
|
|
|
device = "//192.168.178.1/FRITZ.NAS/Backup";
|
|
|
|
|
fsType = "cifs";
|
|
|
|
|
options = [
|
|
|
|
|
"username=ftpuser"
|
|
|
|
|
"password=ftppassword"
|
|
|
|
|
"noauto"
|
|
|
|
|
"nounix"
|
|
|
|
|
"ro"
|
|
|
|
|
"noserverino" # ref https://askubuntu.com/a/1265165
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-25 16:19:21 +02:00
|
|
|
systemd.tmpfiles.rules = [
|
2025-12-25 14:00:03 +01:00
|
|
|
(pkgs.lib.niveum.tmpfilesConfig {
|
2023-07-25 16:19:21 +02:00
|
|
|
type = "L+";
|
|
|
|
|
mode = "0644";
|
|
|
|
|
user = "mpd";
|
|
|
|
|
group = "mpd";
|
|
|
|
|
path = "${config.services.mpd.musicDirectory}/mukke";
|
|
|
|
|
argument = mukkeMountPoint;
|
|
|
|
|
})
|
2025-12-25 14:00:03 +01:00
|
|
|
(pkgs.lib.niveum.tmpfilesConfig {
|
2024-04-03 12:09:49 +02:00
|
|
|
type = "L+";
|
|
|
|
|
mode = "0644";
|
|
|
|
|
user = "mpd";
|
|
|
|
|
group = "mpd";
|
|
|
|
|
path = "${config.services.mpd.musicDirectory}/fritz";
|
|
|
|
|
argument = "${fritzboxMountPoint}";
|
|
|
|
|
})
|
2023-07-25 16:19:21 +02:00
|
|
|
];
|
|
|
|
|
|
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 = [
|
2025-12-25 14:00:03 +01:00
|
|
|
(pkgs.lib.niveum.firewall.accept {
|
2022-03-10 21:52:12 +01:00
|
|
|
inherit dport protocol;
|
|
|
|
|
source = "192.168.0.0/16";
|
|
|
|
|
})
|
2025-12-25 14:00:03 +01:00
|
|
|
(pkgs.lib.niveum.firewall.accept {
|
2022-03-10 21:52:12 +01:00
|
|
|
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];
|
2025-12-25 14:00:03 +01:00
|
|
|
extraCommands = pkgs.lib.niveum.firewall.addRules rules;
|
|
|
|
|
extraStopCommands = pkgs.lib.niveum.firewall.removeRules rules;
|
2021-04-08 19:25:05 +02:00
|
|
|
};
|
|
|
|
|
|
2023-07-25 16:19:21 +02:00
|
|
|
systemd.services.mpd-playlists = {
|
|
|
|
|
before = ["mpd.service"];
|
|
|
|
|
wantedBy = ["mpd.service"];
|
|
|
|
|
script = let
|
|
|
|
|
tags = lib.lists.unique (lib.concatMap ({tags ? [], ...}: tags) streams);
|
|
|
|
|
tagStreams = tag: lib.filter ({tags ? [], ...}: lib.elem tag tags) streams;
|
|
|
|
|
makePlaylist = name: streams: pkgs.writeText "${name}.m3u" (lib.concatMapStringsSep "\n" (lib.getAttr "stream") streams);
|
|
|
|
|
playlistDirectory = pkgs.linkFarm "playlists" (
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name = "all.m3u";
|
|
|
|
|
path = makePlaylist "all" streams;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
++ map (tag: {
|
|
|
|
|
name = "${tag}.m3u";
|
|
|
|
|
path = makePlaylist tag (tagStreams tag);
|
|
|
|
|
})
|
|
|
|
|
tags
|
|
|
|
|
);
|
|
|
|
|
playlistDirectoryPath = "/var/lib/mpd/playlists";
|
|
|
|
|
in ''
|
|
|
|
|
export DI_FM_KEY="$(cat "$CREDENTIALS_DIRECTORY/di-fm-key")"
|
|
|
|
|
|
|
|
|
|
rm -rf ${playlistDirectoryPath}
|
|
|
|
|
mkdir ${playlistDirectoryPath}
|
|
|
|
|
|
|
|
|
|
for m3u in $(ls ${playlistDirectory})
|
|
|
|
|
do
|
|
|
|
|
${pkgs.gnused}/bin/sed s/%DI_FM_KEY%/"$DI_FM_KEY"/g ${playlistDirectory}/"$m3u" > ${playlistDirectoryPath}/"$(basename "$m3u")"
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
LoadCredential = [
|
|
|
|
|
"di-fm-key:${config.age.secrets.di-fm-key.path}"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
2021-04-08 11:59:53 +02:00
|
|
|
|
2022-03-29 20:11:13 +02:00
|
|
|
services.ympd = {
|
|
|
|
|
enable = true;
|
|
|
|
|
mpd.port = config.services.mpd.network.port;
|
2021-01-26 23:05:16 +01:00
|
|
|
};
|
|
|
|
|
|
2023-02-22 10:02:55 +01:00
|
|
|
age.secrets = {
|
2023-02-24 23:10:45 +01:00
|
|
|
ympd-basicAuth = {
|
2023-07-04 16:28:26 +02:00
|
|
|
file = ../../secrets/zaatar-ympd-basicAuth.age;
|
2023-02-24 23:10:45 +01:00
|
|
|
owner = "nginx";
|
|
|
|
|
group = "nginx";
|
|
|
|
|
mode = "400";
|
|
|
|
|
};
|
2023-07-04 16:28:26 +02:00
|
|
|
di-fm-key.file = ../../secrets/di-fm-key.age;
|
2023-02-22 10:02:55 +01:00
|
|
|
};
|
|
|
|
|
|
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" = {
|
2023-02-22 10:02:55 +01:00
|
|
|
basicAuthFile = config.age.secrets.ympd-basicAuth.path;
|
2021-01-26 23:05:16 +01:00
|
|
|
locations."/" = {
|
2022-03-29 20:11:13 +02:00
|
|
|
proxyPass = "http://127.0.0.1:${config.services.ympd.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
|
|
|
}
|