MPD: Difference between revisions
imported>Joeriexelmans Restructure article + add section on PipeWire |
No edit summary |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
== Installation == | [https://www.musicpd.org/ Music Player Daemon] (MPD) is a flexible, powerful, server-side application for playing music. Through plugins and libraries, it can play a variety of sound files while being controlled by its network protocol. | ||
A typical config, running MPD system-wide, will look like this: | |||
== Home-manager Installation == | |||
Home-manager has a module for MPD which runs it as a systemd user service, giving it easier access to your user's sound server. In most cases no specific audio output configuration is necessary: | |||
<syntaxhighlight lang="nix"> | |||
services.mpd = { | |||
enable = true; | |||
musicDirectory = "/path/to/music"; | |||
# Optional: | |||
network.listenAddress = "any"; # if you want to allow non-localhost connections | |||
network.startWhenNeeded = true; # systemd feature: only start MPD service upon connection to its socket | |||
}; | |||
</syntaxhighlight> | |||
== NixOS Installation == | |||
A typical NixOS config, running MPD system-wide, will look like this: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd = { | services.mpd = { | ||
| Line 12: | Line 27: | ||
# Optional: | # Optional: | ||
network.listenAddress = "any"; # if you want to allow non-localhost connections | network.listenAddress = "any"; # if you want to allow non-localhost connections | ||
startWhenNeeded = true; # systemd feature: only start MPD service upon connection to its socket | network.startWhenNeeded = true; # systemd feature: only start MPD service upon connection to its socket | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 18: | Line 33: | ||
== PulseAudio == | == PulseAudio == | ||
In order to use MPD with PulseAudio, enable sound support in the NixOS <code>configuration.nix</code> : | In order to use system-wide MPD with PulseAudio, enable sound support in the NixOS <code>configuration.nix</code> : | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# Enable sound. | # Enable sound. | ||
| Line 92: | Line 107: | ||
== PipeWire == | == PipeWire == | ||
Make sure PipeWire is enabled. See | Make sure PipeWire is enabled. See [[PipeWire]] | ||
To use PipeWire, create an <code>audio_output</code> for it: | To use PipeWire with a system-wide MPD instance, create an <code>audio_output</code> for it: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd.extraConfig = '' | services.mpd.extraConfig = '' | ||
| Line 107: | Line 122: | ||
=== PipeWire workaround === | === PipeWire workaround === | ||
PipeWire typically runs as a normal user, while MPD will run under a system user. A workaround is to configure MPD to run under the same user as PipeWire: | PipeWire typically runs as a normal user, while a system-wide MPD instance will run under a system user. A workaround is to configure MPD to run under the same user as PipeWire: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 113: | Line 128: | ||
systemd.services.mpd.environment = { | systemd.services.mpd.environment = { | ||
# https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/609 | # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/609 | ||
XDG_RUNTIME_DIR = "/run/user/ | XDG_RUNTIME_DIR = "/run/user/${toString config.users.users.userRunningPipeWire.uid}"; # User-id must match above user. MPD will look inside this directory for the PipeWire socket. | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||