{ config, lib, pkgs, ... }: let spotifyd_cache_dir = "/tmp/spotifyd"; cfg = config.grimmShared; spotifyd-dbus = pkgs.writeTextDir "share/dbus-1/system.d/org.mpris.MediaPlayer2.spotifyd.conf" '' ''; in { config = with cfg; lib.mkIf (enable && spotify.enable && spotify.spotifyd.enable) { environment.systemPackages = with pkgs; [ spotifyd spotifyd-dbus ]; systemd.services.init-spotifyd-cache-dir = { description = "Create the spotifyd cache dir"; wantedBy = [ "multi-user.target" ]; serviceConfig.Type = "oneshot"; script = '' mkdir -p ${spotifyd_cache_dir} chown spotifyd:spotifyd -R ${spotifyd_cache_dir} ''; }; # spotifyd config services.spotifyd = { enable = true; settings.global = { bitrate = 320; username = cfg.spotify.spotifyd.username; device_name = "grimm_laptop"; password_cmd = let pass = cfg.spotify.spotifyd.pass; in with lib; if (lib.isPath pass || lib.isString pass) then "${pkgs.coreutils-full}/bin/cat ${pass}" else (getExe pass); device_type = "computer"; dbus_type = "system"; device = "default"; control = "default"; volume_controller = "softvol"; # no_audio_cache = true; spotifyd_cache_dir = spotifyd_cache_dir; max_cache_size = 10000000000; initial_volume = "90"; backend = "alsa"; # fixme }; }; services.dbus.packages = with pkgs; [ spotifyd-dbus ]; # spotifyd has access to global pipewire users.users.spotifyd = { isSystemUser = true; group = "spotifyd"; extraGroups = [ "audio" "pipewire" ]; }; # spotifyd is also a group users.groups = { spotifyd = { }; }; }; options.grimmShared.spotify.spotifyd = with lib; { enable = mkEnableOption "grimm-spotify-tui"; username = mkOption { type = types.nonEmptyStr; description = "spotify username"; }; pass = mkOption { type = types.either types.nonEmptyStr (types.either types.package types.path); description = "command to execute to obtain login information or readable path to a file containing them"; }; }; }