MPD: Difference between revisions

From NixOS Wiki
imported>The pumpkin man
mNo edit summary
imported>Novmar
mNo edit summary
Line 65: Line 65:
   enable = true;
   enable = true;
   extraConfig = "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1"; # Needed by mpd to be able to use Pulseaudio
   extraConfig = "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1"; # Needed by mpd to be able to use Pulseaudio
}
};


# Music daemon, can be accessed through mpc or an other client
# Music daemon, can be accessed through mpc or an other client

Revision as of 22:17, 29 April 2021

Installation

First you have to enable sound support in the NixOS configuration.nix :

# Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;

Now, this article will show you how to setup MPD by using Pulseaudio.

Enable the mpd service :

services.mpd.enable = true;

To specify MPD to output using Pulseaudio, we have to specify audio_output in MPD's configuration :

services.mpd.extraConfig = ''
  audio_output {
    type "pulse"
    name "Pulseaudio"
  }
'';

type is to define whether we are using Pulseaudio or ALSA. name can be what you want.

Now, according to https://wiki.archlinux.org/index.php/Music_Player_Daemon/Tips_and_tricks#Local_(with_separate_mpd_user), this will not work, because MPD and Pulseaudio are ran by different users. Still according to the Arch Wiki, we can "configure mpd to use pulseaudio's tcp module to send sound to localhost".

So, to enable the required Pulseaudio modules, add

hardware.pulseaudio.extraConfig = "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1";

to configuration.nix

And add server "127.0.0.1" to MPD's config to tell it to connect to Pulseaudio's local sound server.

In

services.mpd.extraConfig = ''
  audio_output {
    type "pulse"
    name "Pulseaudio"
  }
'';

Add the server "127.0.0.1" line :

services.mpd.extraConfig = ''
  audio_output {
    type "pulse"
    name "Pulseaudio"
    server "127.0.0.1"
  }
'';

Done ! You can now test if everything is working by using a MPD client, such as MPC.

Note : before testing, restart the MPD service :

# systemctl restart mpd

Summary

# Enable sound.
sound.enable = true;
hardware.pulseaudio = {
  enable = true;
  extraConfig = "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1"; # Needed by mpd to be able to use Pulseaudio
};

# Music daemon, can be accessed through mpc or an other client
services.mpd = {
  enable = true;
  extraConfig = ''
    audio_output {
      type "pulse" # MPD must use Pulseaudio
      name "Pulseaudio" # Whatever you want
      server "127.0.0.1" # MPD must connect to the local sound server
    }
  '';
};

Further reading

The legendary Arch Wiki : https://wiki.archlinux.org/index.php/Mpd