summaryrefslogtreecommitdiff
path: root/nixos/modules/features/mpd/default.nix
blob: a3396225f8d2d136ae4876bdf84c9e6404996fc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{ pkgs, ... }:

{
  # MPD server (music player daemon). The audio_output points at PipeWire
  # through its PulseAudio compatibility layer, since desktop audio is handled
  # by modules/system/audio.
  services.mpd = {
    enable = true;
    user = "seraphim";
    openFirewall = false;
    settings = {
      music_directory = "/mnt/giga/music";
      bind_to_address = "any";
      port = 6600;
      auto_update = "yes";
      audio_output = [
        {
          type = "pulse";
          name = "PipeWire Output";
          mixer_type = "hardware";
        }
      ];
    };
  };

  # MPD runs as a system service, so it needs the per-user runtime dir to
  # reach the PipeWire socket.
  systemd.services.mpd.environment = {
    XDG_RUNTIME_DIR = "/run/user/1000";
  };

  # mpd-mpris bridges MPD to the MPRIS media control interface (used by
  # Waybar/media keys). Lives here because it only matters when MPD is on.
  systemd.user.services.mpd-mpris = {
    description = "MPD MPRIS Service for Waybar";
    wantedBy = [ "default.target" ];
    after = [ "graphical-session.target" ];
    serviceConfig = {
      ExecStart = "${pkgs.mpd-mpris}/bin/mpd-mpris -network tcp -host 127.0.0.1 -port 6600";
      Restart = "on-failure";
    };
  };
}