{ config, pkgs, ... }:

# aplay -l
# aplay --list-pcm
# pacmd list-modules
# pacmd list-cards

{
  services.mpd = {
    enable = true;
    user = "zulumann";
    musicDirectory = "/run/media/zulumann/HDD1.5TB/Audio/Musik";
    playlistDirectory = "/run/media/zulumann/HDD1.5TB/Audio/Playlists";
    network.listenAddress = "any";
    startWhenNeeded = true; # systemd feature: only start MPD service upon connection to its socket    
    extraConfig = ''
      audio_output {
        type                    "alsa"
        name                    "My ALSA"
        device                  "hw:0,0"        # optional 
        format                  "44100:16:2"    # optional
        mixer_type              "hardware"
        mixer_device            "default"
        mixer_control           "PCM"
      }

      audio_output {
        type                    "pipewire"
        name                    "My PipeWire Output"
      }
    '';
  };

  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.
  };

  environment.systemPackages = with pkgs; [
    #gmpc    # Gnome Music Player Client
    cantata
  ];
}