{ config, pkgs, ... }:

let mpdStreamingPort = 8080; in
{
  imports =
    [
      ./common-headless.nix
      ./i3.nix
      ./uefi.nix
      ./fstrim.nix
    ];

  environment.etc."lvm/lvm.conf".text = ''
    devices {
      issue_discards = 1
    }
  '';
  boot.initrd.luks.devices = [
    {
      name = "euhadra_crypt";
      device = "/dev/disk/by-uuid/328a9ede-0958-490b-8e82-62b06b839e21";
      preLVM = true;
      allowDiscards = true;
    }
  ];

  networking.hostName = "euhadra";
  networking.hostId = "ddb5f0fd";

  hardware.cpu.intel.updateMicrocode = true;

  services.mpd = {
    enable = true;
    network.listenAddress = "any";
    musicDirectory = "/mnt/aplysia/music";
    extraConfig = ''
      # audio_output {
      #   type "alsa"
      #   name "dac"
      #   device "sysdefault:CARD=QAMP"
      # }

      audio_output {
        type "pulse"
        name "pulse"
      }

      audio_output {
        type "httpd"
        name "http"
        encoder "flac"
        port "${toString mpdStreamingPort}"
      }

      replaygain "auto"
      restore_paused "yes"
    '';
  };

  networking.firewall.allowedTCPPorts = [
    config.services.mpd.network.port
    4713 # pulseaudio
    mpdStreamingPort # mpd streaming
  ];

  environment.systemPackages = with pkgs; [ mpc_cli ];

  hardware.opengl.extraPackages = [ pkgs.vaapiIntel ];

  nixpkgs.config.mpv.vaapiSupport = true;

  hardware.pulseaudio = {
    systemWide = true;
    zeroconf.publish.enable = true;
    tcp = {
      enable = true;
      anonymousClients.allowedIpRanges = [
        "127.0.0.1"
        "10.57.0.0/16"
      ];
    };
  };

}