From d81e6d4063070ca3b14599df82d3c0457a3266a7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 13 Dec 2019 03:06:01 -0500 Subject: [PATCH] Define systemd service for spotifyd --- modules/audio/spotify.nix | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/modules/audio/spotify.nix b/modules/audio/spotify.nix index b0859217..7b22525d 100644 --- a/modules/audio/spotify.nix +++ b/modules/audio/spotify.nix @@ -1,24 +1,37 @@ { config, lib, pkgs, ... }: -let unstable = import {}; -in { + # services.spotifyd doesn't work so we'll have to roll our own spotifyd + + # spotify-tui solution. I can't get the dbus interface doesn't work, though, + # so we have to wait for spotify-tui to implement CLI command for controlling + # spotify playback (see https://github.com/Rigellute/spotify-tui/issues/147) + # or for spotifyd to get fixed. environment.systemPackages = with pkgs; [ - # services.spotifyd doesn't work so... - spotifyd + unstable.spotifyd (writeScriptBin "spt" '' #!${stdenv.shell} - if ! pgrep -x spotifyd >/dev/null; then - spotifyd --backend pulseaudio \ - --cache_path "$HOME/.cache/spotifyd" \ - --username accounts@v0.io \ - --password $(pass www/spotify.com) + if ! systemctl --user is-active spotifyd >/dev/null; then + systemctl --user start spotifyd fi ${unstable.spotify-tui}/bin/spt '') # spotify-tui is fine for selecting and playing music, but incomplete. We - # occasionally still need the official client. + # occasionally still need the official client for more sophisticated search + # and the "made for you" playlists. spotify ]; + + systemd.user.services.spotifyd.serviceConfig = + let spotifydConf = pkgs.writeText "spotifyd.conf" '' + [global] + username = accounts@v0.io + password_cmd = ${pkgs.pass}/bin/pass www/spotify.com | head -n1 + backend = pulseaudio + ''; + in { + ExecStart = "${pkgs.unstable.spotifyd}/bin/spotifyd --no-daemon --cache-path /tmp/spotifyd --config-path ${spotifydConf}"; + Restart = "always"; + RestartSec = 6; + }; }