MPD: Difference between revisions
→NixOS installation: correction: startWhenNeeded is no longer under the network attribute. |
Migrated services.mpd.extraConfig to services.mpd.settings with proper Nix attribute set syntax. |
||
| Line 18: | Line 18: | ||
enable = true; | enable = true; | ||
musicDirectory = "/path/to/music"; | musicDirectory = "/path/to/music"; | ||
settings = { | |||
# must specify one or more | # must specify one or more audio_output blocks in order to play audio! | ||
# (e.g. ALSA, PulseAudio, PipeWire), see next sections | # (e.g. ALSA, PulseAudio, PipeWire), see next sections | ||
}; | |||
# Optional: | # Optional: | ||
| Line 40: | Line 40: | ||
Then, add a PulseAudio output to MPD: | Then, add a PulseAudio output to MPD: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd. | services.mpd.settings = { | ||
audio_output { | audio_output = [ | ||
{ | |||
type = "pulse"; | |||
} | name = "My PulseAudio"; # this can be whatever you want | ||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 60: | Line 62: | ||
And add <code>server "127.0.0.1"</code> to MPD's config to tell it to connect to PulseAudio's local sound server. | And add <code>server "127.0.0.1"</code> to MPD's config to tell it to connect to PulseAudio's local sound server. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd. | services.mpd.settings = { | ||
audio_output { | audio_output = [ | ||
{ | |||
type = "pulse"; | |||
name = "Pulseaudio"; | |||
} | server = "127.0.0.1"; # add this line - MPD must connect to the local sound server | ||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
After editing the configuration and running <code># nixos-rebuild switch</code>, you can test if everything is working by using a MPD client, such as <code>MPC</code>. | After editing the configuration and running <code># nixos-rebuild switch</code>, you can test if everything is working by using a MPD client, such as <code>MPC</code>. | ||
| Line 74: | Line 78: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
hardware.pulseaudio.systemWide = true; | hardware.pulseaudio.systemWide = true; | ||
services.mpd. | services.mpd.settings = { | ||
audio_output = [ | |||
type "pulse" | { | ||
name "Pulseaudio" | type = "pulse"; | ||
mixer_type | name = "Pulseaudio"; | ||
mixer_device | mixer_type = "hardware"; # optional | ||
mixer_control | mixer_device = "default"; # optional | ||
mixer_index | mixer_control = "PCM"; # optional | ||
} | mixer_index = "0"; # optional | ||
} | |||
]; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 91: | Line 97: | ||
You can also use alsa, just add audio output to services.mpd.extraConfig: | You can also use alsa, just add audio output to services.mpd.extraConfig: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd. | services.mpd.settings = { | ||
audio_output { | audio_output = [ | ||
{ | |||
type = "alsa"; | |||
name = "My ALSA"; | |||
device = "hw:0,0"; # optional | |||
format = "44100:16:2"; # optional | |||
mixer_type = "hardware"; | |||
mixer_device = "default"; | |||
} | mixer_control = "PCM"; | ||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 109: | Line 117: | ||
To use PipeWire with a system-wide MPD instance, 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. | services.mpd.settings = { | ||
audio_output { | audio_output = [ | ||
{ | |||
type = "pipewire"; | |||
} | name = "My PipeWire Output"; | ||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
See https://mpd.readthedocs.io/en/stable/plugins.html#pipewire for more options. | See https://mpd.readthedocs.io/en/stable/plugins.html#pipewire for more options. | ||
| Line 123: | Line 133: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.mpd. | services.mpd.settings = { | ||
audio_output = [ | |||
{ | |||
type = "pipewire"; | |||
name = "My PipeWire Output"; | |||
} | |||
]; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||