1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/systems/zaatar/mpd.nix

125 lines
3.3 KiB
Nix
Raw Normal View History

2022-03-10 21:52:12 +01:00
{
config,
pkgs,
lib,
...
}: let
firewall = (import ../../lib).firewall lib;
inherit (import ../../lib) tmpfilesConfig;
streams = import ../../lib/streams.nix {
di-fm-key = ""; # TODO lib.strings.fileContents <secrets/di.fm/key>;
2021-01-27 00:03:32 +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";
cert = config.age.secrets.syncthing-cert.path;
key = config.age.secrets.syncthing-key.path;
2021-12-01 09:47:14 +01:00
devices = {
inherit ((import ../../lib).syncthing.devices) kabsa manakish heym;
2021-12-01 09:47:14 +01:00
};
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
};
};
services.mpd = {
enable = true;
network.listenAddress = "0.0.0.0";
extraConfig = ''
log_level "default"
auto_update "yes"
audio_output {
2021-04-03 15:01:54 +02:00
type "pulse"
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
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";
})
];
in {
2022-03-10 21:52:12 +01:00
allowedTCPPorts = [80];
extraCommands = firewall.addRules rules;
extraStopCommands = firewall.removeRules rules;
};
# 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";
path = "/var/lib/mpd/playlists/all.m3u";
2022-04-10 19:38:41 +02:00
argument = makePlaylist "all" streams;
})
];
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
};
age.secrets = {
ympd-basicAuth.file = ../../secrets/zaatar-ympd-basicAuth.age;
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;
};
2021-01-26 23:05:16 +01:00
services.nginx = {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
2021-09-19 11:41:36 +02:00
virtualHosts."radio.kmein.r" = {
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}";
proxyWebsockets = true;
2021-01-26 23:05:16 +01:00
};
};
};
}