2020-05-20 00:06:26 +02:00
|
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
|
|
let
|
|
|
|
|
|
inherit (lib.strings) fileContents;
|
2020-06-10 17:37:25 +02:00
|
|
|
|
in {
|
|
|
|
|
|
environment.systemPackages = with pkgs; [ spotify spotify-tui playerctl ];
|
2020-05-20 00:06:26 +02:00
|
|
|
|
|
2020-05-20 20:45:00 +02:00
|
|
|
|
# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/audio/spotifyd.nix
|
2020-06-10 17:37:25 +02:00
|
|
|
|
systemd.user.services.spotifyd = let
|
2020-05-20 20:45:00 +02:00
|
|
|
|
spotifyd = pkgs.unstable.spotifyd.override {
|
|
|
|
|
|
withMpris = true;
|
|
|
|
|
|
withPulseAudio = true;
|
|
|
|
|
|
inherit (pkgs) libpulseaudio dbus;
|
|
|
|
|
|
};
|
2020-06-10 17:37:25 +02:00
|
|
|
|
spotifydConf = pkgs.writeText "spotifyd.conf" (lib.generators.toINI { } {
|
2020-05-20 00:06:26 +02:00
|
|
|
|
global = {
|
2020-09-24 19:25:47 +02:00
|
|
|
|
username = fileContents <secrets/spotify/username>;
|
|
|
|
|
|
password = fileContents <secrets/spotify/password>;
|
2020-05-20 20:45:00 +02:00
|
|
|
|
backend = "pulseaudio";
|
|
|
|
|
|
on_song_change_hook = toString (pkgs.writers.writeDash "songinfo" ''
|
2020-06-10 17:37:25 +02:00
|
|
|
|
PATH=$PATH:${
|
|
|
|
|
|
lib.makeBinPath [ pkgs.playerctl pkgs.gawk pkgs.libnotify ]
|
|
|
|
|
|
}
|
2020-05-20 20:45:00 +02:00
|
|
|
|
metadata=$(playerctl metadata --player spotifyd)
|
2020-05-24 10:08:23 +02:00
|
|
|
|
title=$(echo "$metadata" | awk '/^xesam:title\s/ { print substr($0, index($0, $3)) }')
|
|
|
|
|
|
artist=$(echo "$metadata" | awk '/^xesam:artist\s/ { print substr($0, index($0, $3)) }' | paste --serial --delimiters "/")
|
|
|
|
|
|
album=$(echo "$metadata" | awk '/^xesam:album\s/ { print substr($0, index($0, $3)) }')
|
|
|
|
|
|
notify-send --app-name=" Spotify" "$title" "$artist – $album"
|
2020-05-20 20:45:00 +02:00
|
|
|
|
'');
|
2020-05-20 00:06:26 +02:00
|
|
|
|
};
|
2020-05-20 20:45:00 +02:00
|
|
|
|
});
|
|
|
|
|
|
in {
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
after = [ "network-online.target" "sound.target" ];
|
|
|
|
|
|
description = "spotifyd, a Spotify playing daemon";
|
|
|
|
|
|
serviceConfig = {
|
2020-06-10 17:37:25 +02:00
|
|
|
|
ExecStart =
|
|
|
|
|
|
"${spotifyd}/bin/spotifyd --no-daemon --config-path ${spotifydConf}";
|
2020-05-20 20:45:00 +02:00
|
|
|
|
Restart = "always";
|
|
|
|
|
|
RestartSec = 12;
|
2020-05-20 00:06:26 +02:00
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|