86 lines
3.1 KiB
Nix
86 lines
3.1 KiB
Nix
|
{ pkgs, lib, config, ... }:
|
||
|
let tomlFormat = pkgs.formats.toml { }; in {
|
||
|
options = {
|
||
|
services.custom.rescrobbled = {
|
||
|
enable = lib.mkEnableOption "rescrobbled";
|
||
|
|
||
|
package = lib.mkOption {
|
||
|
type = lib.types.package;
|
||
|
default = (pkgs.callPackage ../../packages/rescrobbled {});
|
||
|
defaultText = lib.literalExpression "pkgs.rescrobbled";
|
||
|
description = "The package to use for rescrobbled";
|
||
|
};
|
||
|
|
||
|
session = lib.mkOption {
|
||
|
type = lib.types.str;
|
||
|
description = ''
|
||
|
The session token to use for last.fm.
|
||
|
This can be found by setting a last.fm API key & secret,
|
||
|
and then manually running the daemon. Then, the session token
|
||
|
will be located at {file}`$XDG_CONFIG_HOME/rescrobbled/session`.
|
||
|
'';
|
||
|
default = null;
|
||
|
};
|
||
|
|
||
|
settings = lib.mkOption {
|
||
|
type = tomlFormat.type;
|
||
|
default = {};
|
||
|
example = lib.literalExpression ''
|
||
|
lastfm-key = "Last.fm API key"
|
||
|
lastfm-secret = "Last.fm API secret"
|
||
|
min-play-time = 0
|
||
|
player-whitelist = [ "Player MPRIS identity or bus name" ]
|
||
|
filter-script = "path/to/script"
|
||
|
|
||
|
[[listenbrainz]]
|
||
|
url = "Custom API URL"
|
||
|
token = "User token"
|
||
|
'';
|
||
|
description = ''
|
||
|
Configuration written to
|
||
|
{file}`$XDG_CONFIG_HOME/rescrobbled/config.toml`.
|
||
|
|
||
|
See <https://github.com/InputUsername/rescrobbled#configuration> for the full list
|
||
|
of options.
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config = let cfg = config.services.custom.rescrobbled; in lib.mkIf cfg.enable {
|
||
|
home.packages = [ cfg.package ];
|
||
|
|
||
|
xdg.configFile ={
|
||
|
"rescrobbled/config.toml" = lib.mkIf (cfg.settings != { }) {
|
||
|
enable = true;
|
||
|
|
||
|
source = tomlFormat.generate "rescrobbled-config" cfg.settings;
|
||
|
};
|
||
|
|
||
|
"rescrobbled/session" = lib.mkIf (cfg.settings != { }) {
|
||
|
enable = true;
|
||
|
# Force makes it easy to generate the session file, then add it to nix cfg without issues
|
||
|
force = true;
|
||
|
|
||
|
text = cfg.session;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
systemd.user.services.rescrobbled = {
|
||
|
Unit = {
|
||
|
Description = "An MPRIS scrobbler";
|
||
|
Documentation = "https://github.com/InputUsername/rescrobbled";
|
||
|
Wants = "network-online.target";
|
||
|
After = "network-online.target";
|
||
|
};
|
||
|
|
||
|
Service = {
|
||
|
ExecStartPre = "${pkgs.coreutils}/bin/sleep 15"; # Avoid listenbrainz errors by adding delay till network is connected
|
||
|
ExecStart = "${cfg.package}/bin/rescrobbled";
|
||
|
};
|
||
|
|
||
|
Install.WantedBy = [ "default.target" ];
|
||
|
};
|
||
|
};
|
||
|
}
|