Running mpd as a user service

Hello everyone!

(This is my first post here, please do point out when I’m not adhering to community rules/standards)

I have been trying (with no luck) to run mpd in nixos with no luck so far. I think my problem boils down to the mpd.service not being started as a user service.
Running journalctl -u mpd yields:

Jan 04 00:09:58 nix systemd[1]: Starting Music Player Daemon...
Jan 04 00:09:58 nix mpd[802375]: exception: Failed to access /home/moz/Music: Permission denied
Jan 04 00:09:58 nix mpd[802375]: exception: Failed to open '/var/lib/mpd/tag_cache': No such file or directory
Jan 04 00:09:58 nix mpd[802375]: zeroconf: No global port, disabling zeroconf
Jan 04 00:09:58 nix mpd[802375]: exception: Failed to open '/var/lib/mpd/state': No such file or directory
Jan 04 00:09:58 nix mpd[802375]: exception: Failed to access /home/moz/Music: Permission denied
Jan 04 00:09:58 nix systemd[1]: Started Music Player Daemon.
Jan 04 00:14:20 nix systemd[1]: Stopping Music Player Daemon...
Jan 04 00:14:20 nix systemd[1]: mpd.service: Deactivated successfully.
Jan 04 00:14:20 nix systemd[1]: Stopped Music Player Daemon.
Jan 04 00:15:04 nix systemd[1]: Starting Music Player Daemon...
Jan 04 00:15:04 nix mpd[804635]: zeroconf: No global port, disabling zeroconf
Jan 04 00:15:04 nix systemd[1]: Started Music Player Daemon.
Jan 04 00:15:19 nix systemd[1]: Stopping Music Player Daemon...
Jan 04 00:15:19 nix systemd[1]: mpd.service: Deactivated successfully.
Jan 04 00:15:19 nix systemd[1]: Stopped Music Player Daemon.
-- Boot 506eaa85f8564501819c314721c2451f --
Jan 04 00:16:08 nix systemd[1]: Starting Music Player Daemon...
Jan 04 00:16:08 nix mpd[3248]: zeroconf: No global port, disabling zeroconf
Jan 04 00:16:08 nix systemd[1]: Started Music Player Daemon.
Jan 04 11:34:19 nix systemd[1]: Stopping Music Player Daemon...
Jan 04 11:34:19 nix systemd[1]: mpd.service: Deactivated successfully.
Jan 04 11:34:19 nix systemd[1]: Stopped Music Player Daemon.
Jan 04 11:34:19 nix systemd[1]: mpd.service: Consumed 215ms CPU time, read 28.6M from disk, written 0B to disk, no IP traffic.

The relevant part in my configuration.nix reads

 # MPD
  services.mpd = {
  enable = true;
  musicDirectory = "/home/moz/Music";
  extraConfig = ''
  audio_output {
    type "pipewire"
    name "My PipeWire Output"
  }
  '';
  user = "moz";
  # Optional:
  network.listenAddress = "any"; # if you want to allow non-localhost connections
  startWhenNeeded = true; # systemd feature: only start MPD service upon connection to its socket
  };
  systemd.services.mpd.environment = {
   # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/609
   XDG_RUNTIME_DIR = "/run/user/1000"; # User-id 1000 must match above user. MPD will look inside this directory for the PipeWire socket.
   };

Furthermore simply running mpd yields:
exception: No configuration file found

As far as I can tell I’ve just followed the instructions given in the wiki. And yet the service doesn’t seem to run as a user service.

Any help is much appreciated

I solved it!

All I needed to do was run a database update with Ctrl-U in ncmpcpp and now it seems to work.

1 Like