2022-03-10 21:52:12 +01:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
pkgs,
|
|
|
|
|
lib,
|
|
|
|
|
...
|
|
|
|
|
}: let
|
2023-02-22 10:02:55 +01:00
|
|
|
firewall = (import ../../lib).firewall lib;
|
|
|
|
|
inherit (import ../../lib) tmpfilesConfig;
|
2021-04-08 19:25:05 +02:00
|
|
|
|
2023-07-13 22:13:22 +02:00
|
|
|
mukkeMountPoint = "/mnt/mukke";
|
|
|
|
|
|
2023-02-22 10:02:55 +01:00
|
|
|
streams = import ../../lib/streams.nix {
|
|
|
|
|
di-fm-key = ""; # TODO lib.strings.fileContents <secrets/di.fm/key>;
|
2021-01-27 00:03:32 +01:00
|
|
|
};
|
2021-01-27 08:22:03 +01:00
|
|
|
multi-room-audio-port = 8000;
|
2022-03-10 21:52:12 +01:00
|
|
|
in {
|
|
|
|
|
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";
|
2023-02-22 10:02:55 +01:00
|
|
|
cert = config.age.secrets.syncthing-cert.path;
|
|
|
|
|
key = config.age.secrets.syncthing-key.path;
|
2021-12-01 09:47:14 +01:00
|
|
|
devices = {
|
2023-02-22 10:02:55 +01:00
|
|
|
inherit ((import ../../lib).syncthing.devices) kabsa manakish heym;
|
2021-12-01 09:47:14 +01:00
|
|
|
};
|
2023-07-13 22:13:22 +02:00
|
|
|
folders."${config.services.mpd.musicDirectory}/sync" = {
|
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"
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
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"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-30 09:47:50 +01:00
|
|
|
# to reset:
|
|
|
|
|
# ssh zaatar 'rm /var/lib/mpd/playlists/*.m3u && systemd-tmpfiles --create'
|
2022-04-10 19:38:41 +02:00
|
|
|
systemd.tmpfiles.rules = let
|
2022-03-29 20:11:13 +02:00
|
|
|
tags = lib.lists.unique (lib.concatMap ({tags ? [], ...}: tags) streams);
|
2022-04-15 01:17:38 +02:00
|
|
|
tagStreams = tag: lib.filter ({tags ? [], ...}: lib.elem tag tags) streams;
|
|
|
|
|
makePlaylist = name: streams: pkgs.writeText "${name}.m3u" (lib.concatMapStringsSep "\n" (lib.getAttr "stream") streams);
|
2022-04-10 19:38:41 +02:00
|
|
|
in
|
|
|
|
|
map (tag:
|
|
|
|
|
tmpfilesConfig {
|
|
|
|
|
type = "L+";
|
|
|
|
|
path = "/var/lib/mpd/playlists/${tag}.m3u";
|
|
|
|
|
mode = "0644";
|
|
|
|
|
user = "mpd";
|
|
|
|
|
group = "mpd";
|
|
|
|
|
argument = makePlaylist tag (tagStreams tag);
|
|
|
|
|
})
|
|
|
|
|
tags
|
2022-04-15 01:17:38 +02:00
|
|
|
++ [
|
2022-04-10 19:38:41 +02:00
|
|
|
(tmpfilesConfig {
|
|
|
|
|
type = "L+";
|
|
|
|
|
mode = "0644";
|
|
|
|
|
user = "mpd";
|
|
|
|
|
group = "mpd";
|
2023-01-30 09:47:50 +01:00
|
|
|
path = "/var/lib/mpd/playlists/all.m3u";
|
2022-04-10 19:38:41 +02:00
|
|
|
argument = makePlaylist "all" streams;
|
|
|
|
|
})
|
2023-07-13 22:13:22 +02:00
|
|
|
(tmpfilesConfig {
|
|
|
|
|
type = "L+";
|
|
|
|
|
mode = "0644";
|
|
|
|
|
user = "mpd";
|
|
|
|
|
group = "mpd";
|
|
|
|
|
path = "${config.services.mpd.musicDirectory}/mukke";
|
|
|
|
|
argument = mukkeMountPoint;
|
|
|
|
|
})
|
2022-04-10 19:38:41 +02:00
|
|
|
];
|
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
|
|
|
syncthing-cert.file = ../../secrets/zaatar-syncthing-cert.age;
|
|
|
|
|
syncthing-key.file = ../../secrets/zaatar-syncthing-key.age;
|
|
|
|
|
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
|
|
|
}
|