home/mpd: misc upgrades

This commit is contained in:
Oystein Kristoffer Tveit 2024-11-19 13:54:15 +01:00
parent 4e1eb31336
commit 3efeeed023
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 128 additions and 15 deletions

View File

@ -1,4 +1,4 @@
{pkgs, ...}: { config, pkgs, ... }:
{ {
programs.ncmpcpp = { programs.ncmpcpp = {
enable = true; enable = true;
@ -332,11 +332,11 @@
window_border_color = "green"; window_border_color = "green";
active_window_border = "red"; active_window_border = "red";
visualizer_data_source = "/tmp/mpd.fifo"; visualizer_data_source = "/run/user/${toString config.home.uid}/mpd/visualizer.fifo";
visualizer_output_name = "Visualizer feed"; visualizer_output_name = "Visualizer feed";
visualizer_in_stereo = "no"; visualizer_in_stereo = "no";
visualizer_type = "spectrum"; # spectrum, ellipse, wave_filled, wave # visualizer_type = "spectrum"; # spectrum, ellipse, wave_filled, wave
visualizer_look = "+"; # wave | spectrum, ellipse, wave_filled # visualizer_look = "+█"; # wave | spectrum, ellipse, wave_filled
}; };
}; };
} }

View File

@ -1,28 +1,141 @@
{ config, ... }: { config, pkgs, lib, ... }:
let
cfg = config.services.mpd;
in
{ {
services.mpd = rec { services.mpd = {
enable = true; enable = true;
musicDirectory = config.xdg.userDirs.music; musicDirectory = config.xdg.userDirs.music;
playlistDirectory = "${musicDirectory}/playlists/MPD"; playlistDirectory = "${cfg.musicDirectory}/playlists/MPD";
network.startWhenNeeded = true; network.startWhenNeeded = true;
# TODO: make the path specific to the user unit
extraConfig = '' extraConfig = ''
audio_output { pid_file "/run/user/${toString config.home.uid}/mpd/pid"
type "fifo"
name "Visualizer feed" zeroconf_enabled "no"
path "/tmp/mpd.fifo"
format "44100:16:2" replaygain "auto"
}
restore_paused "yes"
auto_update "no"
audio_output { audio_output {
type "pipewire" type "pipewire"
name "PipeWire Sound Server" name "PipeWire Sound Server"
} }
audio_output {
type "fifo"
name "Visualizer feed"
path "/run/user/${toString config.home.uid}/mpd/visualizer.fifo"
format "44100:16:2"
}
resampler {
plugin "soxr"
quality "very high"
}
playlist_plugin {
name "cue"
enabled "true"
}
playlist_plugin {
name "m3u"
enabled "true"
}
playlist_plugin {
name "extm3u"
enabled "true"
}
playlist_plugin {
name "flac"
enabled "true"
}
playlist_plugin {
name "rss"
enabled "true"
}
''; '';
}; };
# TODO: disable auto_update and use systemd path to listen for changes
# TODO: upstream unix socket support to home-manager # TODO: upstream unix socket support to home-manager
systemd.user.services.mpd = {
Unit = {
Documentation = [
"man:mpd(1)"
"man:mpd.conf(5)"
];
};
Service = {
WatchdogSec = 120;
# for io_uring
LimitMEMLOCK = "64M";
# allow MPD to use real-time priority 40
LimitRTPRIO = 40;
LimitRTTIME = "infinity";
PrivateUsers = true;
ProtectSystem = true;
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_UNIX"
];
RestrictNamespaces = true;
};
};
systemd.user.paths.mpd-update-library = {
Unit = {
Description = "Watchdog that updates the mpd library whenever the files are modified";
Documentation = [
"man:mpd(1)"
"man:mpd.conf(5)"
];
WantedBy = [ "paths.target" ];
};
Path = {
PathChanged = cfg.musicDirectory;
Unit = "mpd-update-library.service";
TriggerLimitIntervalSec = "1s";
TriggerLimitBurst = "1";
};
};
systemd.user.services.mpd-update-library = {
Unit = {
Description = "Watchdog that updates the mpd library whenever the files are modified";
Documentation = [
"man:mpd(1)"
"man:mpd.conf(5)"
];
};
Service = {
Type = "oneshot";
ExecStart = "${lib.getExe pkgs.mpc-cli} update --wait";
PrivateUsers = true;
ProtectSystem = true;
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_UNIX"
];
RestrictNamespaces = true;
};
};
} }