{ config, lib, pkgs, ... }: with lib; let cfg = config.roles.spotifyd; spotifyd = pkgs.spotifyd.override { withMpris = true; withPulseAudio = true; }; spotifydConf = pkgs.writeText "spotifyd-config" '' [global] backend = "pulseaudio" bitrate = 320 use_mpris = false zeroconf_port = 5354 autoplay = false device_type = "${cfg.deviceType}" ''; in { options.roles.spotifyd = { enable = mkEnableOption "Enable the spotifyd role"; deviceType = mkOption { default = "computer"; }; }; config = mkIf cfg.enable { roles.audio.enable = true; systemd.user.services.spotifyd = { enable = true; wantedBy = [ "default.target" ]; after = [ "network-online.target" "sound.target" ]; description = "spotifyd, a Spotify playing daemon"; serviceConfig = { ExecStart = "${spotifyd}/bin/spotifyd --no-daemon --cache-path=\${HOME}/.cache/spotifyd --config-path=${spotifydConf}"; Restart = "always"; RestartSec = 12; }; }; users.users."kodi".linger = true; networking.firewall.allowedTCPPorts = [ 5354 57621 ]; networking.firewall.allowedUDPPorts = [ 5353 ]; }; }