Nixpkgs: Mopidy is unable to connect to pulseaudio

Created on 28 Apr 2018  路  4Comments  路  Source: NixOS/nixpkgs

Issue description

Mopidy, either in its default configuration for [audio] or with the nixos equivalent of the described documentation at https://docs.mopidy.com/en/latest/service/#configure-pulseaudio is unable to properly use pulseaudio, so it can't play any music

Steps to reproduce

Configure pulseaudio as following

  hardware.pulseaudio = {
    enable = true;
    support32Bit = true;
    tcp.enable = true;
  };

The main important bit is tcp.enable = true

Then in config for mopidy we have

  services.mopidy = {
    enable = true;
    extensionPackages = [ pkgs.mopidy-spotify];
    configuration = ''
      [spotify]
      enabled = true
      username = REMOVED
      password = REMOVED

      client_id = REMOVED
      client_secret = REMOVED

      bitrate = 320

      [audio]
      output = pulsesink server=127.0.0.1
    '';
  };

The important bit being

      [audio]
      output = pulsesink server=127.0.0.1

Then when trying to play a song, nothing plays. Using systemctl status mopidy I get

Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Track is not playable: spotify:track:6gnddzclPNSfTVc1zRW5ML
Apr 28 02:53:02 nixos mopidy[14775]: ERROR    GStreamer error: gst-resource-error-quark: Failed to connect: Connection refused (1)
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Setting GStreamer state to GST_STATE_PLAYING failed
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Track is not playable: spotify:track:0aqRkWPAL9BGCvvdSiXaE9
Apr 28 02:53:02 nixos mopidy[14775]: ERROR    GStreamer error: gst-resource-error-quark: Failed to connect: Connection refused (1)
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Setting GStreamer state to GST_STATE_PLAYING failed
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Track is not playable: spotify:track:6THch1lM2n5vcv4aG4efjH
Apr 28 02:53:02 nixos mopidy[14775]: ERROR    GStreamer error: gst-resource-error-quark: Failed to connect: Connection refused (1)
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Setting GStreamer state to GST_STATE_PLAYING failed
Apr 28 02:53:02 nixos mopidy[14775]: WARNING  Track is not playable: spotify:track:2sXZV2KTxprwStuhQ7zJ2f

Note that doing

hardware.pulseaudio = {
  enable = true;
  package = pulseaudioFull;
  configFile = pkgs.writeText "default.pa" ''
    load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
  '';
};

Doesn't seem to work either (as suggested at https://www.reddit.com/r/NixOS/comments/84h7ks/pulseaudio_with_mopidy/ Using the tcp.enable config should amount to the same thing however).

Note that if you remove the [audio] config entirely and just let mopidy use the default audio settings, you get this instead

Apr 28 03:11:35 nixos pulseaudio[17077]: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Apr 28 03:11:35 nixos pulseaudio[17077]: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

Technical details

 - system: `"x86_64-linux"`
 - host os: `Linux 4.9.86, NixOS, 17.09.3243.bca2ee28db4 (Hummingbird)`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 1.11.16`
 - channels(root): `"nixos-17.09.3243.bca2ee28db4"`
 - channels(mdedetrich): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs`

Most helpful comment

Hope you don't mind me hijacking this thread, but I put a good couple of hours into getting mopidy to work on NixOS and this thread is one of the first search results when trying to troubleshoot problems.

The above config lead to the error messages to disappear in the mopidy log. However, I could still not play any music. Mopidy's debug output also stated that it successfully connected to pulseaudio, so I really don't know where the problem was.

Eventually I was able to solve it by simply enabling pulseaudio system-wide and leaving all the default settings from mopidy (no config needed):

services.mopidy.enable = true;

hardware.pulseaudio = {                                                                 
      enable = true;                                                               
      systemWide = true;                                                                                             
}; 

In hindsight, I should have tried this much earlier...

All 4 comments

I have just updated to 18.03 and problem still persists

Have you tried enabling anonymous clients in your ip range?

I think I had to do

    tcp = {
      enable = true;
      anonymousClients.allowedIpRanges = [ "127.0.0.1" ];
    };

but I'm not sure where that came from.

@johnchildren I tried doing this, still no difference, here are my configs for reference

  hardware.pulseaudio = {
    enable = true;
    support32Bit = true;
    tcp = {
      enable = true;
      anonymousClients.allowedIpRanges = ["127.0.0.1"];
    };
  };
  services.mopidy = {
    enable = true;
    extensionPackages = [ pkgs.mopidy-spotify];
    configuration = ''
      [spotify]
      enabled = true
      username = <REMOVED>
      password = <REMOVED>

      client_id = <REMOVED>
      client_secret = <REMOVED>

      bitrate = 320

      [audio]
      output = pulsesink server=127.0.0.1
    '';
  };

EDIT NVM, had to reboot and now its working. Closing ticket

Hope you don't mind me hijacking this thread, but I put a good couple of hours into getting mopidy to work on NixOS and this thread is one of the first search results when trying to troubleshoot problems.

The above config lead to the error messages to disappear in the mopidy log. However, I could still not play any music. Mopidy's debug output also stated that it successfully connected to pulseaudio, so I really don't know where the problem was.

Eventually I was able to solve it by simply enabling pulseaudio system-wide and leaving all the default settings from mopidy (no config needed):

services.mopidy.enable = true;

hardware.pulseaudio = {                                                                 
      enable = true;                                                               
      systemWide = true;                                                                                             
}; 

In hindsight, I should have tried this much earlier...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grahamc picture grahamc  路  3Comments

copumpkin picture copumpkin  路  3Comments

ghost picture ghost  路  3Comments

teto picture teto  路  3Comments

sid-kap picture sid-kap  路  3Comments