2024-05-24 21:11:11 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (pkgs) writeShellScriptBin;
|
|
|
|
inherit (builtins) toFile;
|
|
|
|
|
|
|
|
rcloneConfig = toFile "rclone.conf" ''
|
|
|
|
[Music]
|
|
|
|
type = webdav
|
|
|
|
url = https://storage-webdav.owo.monster/MusicRO/
|
|
|
|
vendor = other
|
|
|
|
'';
|
|
|
|
|
|
|
|
mountMusic = pkgs.writeShellScriptBin "mount-music" ''
|
|
|
|
umount -flR /Music || true
|
|
|
|
rclone --config ${rcloneConfig} mount Music: /Music \
|
|
|
|
--allow-other \
|
|
|
|
--uid=${toString config.users.users.mpd.uid} \
|
|
|
|
--gid=${toString config.users.groups.mpd.gid} \
|
|
|
|
--fast-list \
|
|
|
|
--umask=666 \
|
|
|
|
--cache-dir=/root/.cache/music-mount \
|
|
|
|
--dir-cache-time=60m \
|
|
|
|
--vfs-cache-mode=full \
|
|
|
|
--vfs-cache-max-size=2g \
|
|
|
|
--vfs-cache-max-age=7d \
|
|
|
|
--log-level=INFO "$@"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
rclone
|
|
|
|
(writeShellScriptBin "rclone-music" ''
|
|
|
|
rclone --config ${rcloneConfig} "$@"
|
|
|
|
'')
|
|
|
|
fuse
|
|
|
|
fuse3
|
|
|
|
mountMusic
|
|
|
|
];
|
|
|
|
|
|
|
|
programs.fuse.userAllowOther = true;
|
|
|
|
|
|
|
|
systemd.services.music-mount = {
|
|
|
|
wantedBy = ["mpd.service"];
|
|
|
|
partOf = ["mpd.service"];
|
|
|
|
path = with pkgs; [
|
|
|
|
fuse
|
|
|
|
fuse3
|
2024-05-24 21:16:35 +01:00
|
|
|
rclone
|
|
|
|
util-linux
|
2024-05-24 21:11:11 +01:00
|
|
|
];
|
|
|
|
serviceConfig.ExecStart = "${mountMusic}/bin/mount-music --syslog";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /Music - mpd mpd"
|
|
|
|
|
|
|
|
"d /root/.cache - root root"
|
|
|
|
"d /root/.cache/music-mount - root root"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.mpd = {
|
|
|
|
wants = ["music-mount.service"];
|
|
|
|
after = ["music-mount.service"];
|
|
|
|
serviceConfig = {
|
|
|
|
ReadOnlyPaths = "/Music";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|