MPD: Difference between revisions

Jasi (talk | contribs)
NixOS installation: correction: startWhenNeeded is no longer under the network attribute.
Novida (talk | contribs)
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";
   extraConfig = ''
   settings = {
     # must specify one or more outputs in order to play audio!
     # 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.extraConfig = ''
services.mpd.settings = {
   audio_output {
   audio_output = [
    type "pulse"
    {
    name "My PulseAudio" # this can be whatever you want
      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.extraConfig = ''
services.mpd.settings = {
   audio_output {
   audio_output = [
    type "pulse"
    {
    name "Pulseaudio"
      type = "pulse";
    server "127.0.0.1" # add this line - MPD must connect to the local sound server
      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.extraConfig = ''
services.mpd.settings = {
     audio_output {
  audio_output = [
       type "pulse"
     {
       name "Pulseaudio"
       type = "pulse";
       mixer_type     "hardware"     # optional
       name = "Pulseaudio";
       mixer_device   "default"       # optional
       mixer_type   = "hardware"; # optional
       mixer_control   "PCM"           # optional
       mixer_device = "default"# optional
       mixer_index     "0"             # optional
       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.extraConfig = ''
services.mpd.settings = {
   audio_output {
   audio_output = [
    type "alsa"
    {
    name "My ALSA"
      type = "alsa";
    device "hw:0,0" # optional  
      name = "My ALSA";
    format "44100:16:2" # optional
      device       = "hw:0,0"; # optional
    mixer_type "hardware"
      format       = "44100:16:2"; # optional
    mixer_device "default"
      mixer_type   = "hardware";
    mixer_control "PCM"
      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.extraConfig = ''
services.mpd.settings = {
   audio_output {
   audio_output = [
    type "pipewire"
    {
    name "My PipeWire 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.user = "userRunningPipeWire";
services.mpd.settings = {
systemd.services.mpd.environment = {
  audio_output = [
    # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/609
    {
    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.
      type = "pipewire";
      name = "My PipeWire Output";
    }
  ];
};
};
</syntaxhighlight>
</syntaxhighlight>