2020-10-12 00:22:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.mpdris2;
|
|
|
|
|
|
|
|
toIni = generators.toINI {
|
|
|
|
mkKeyValue = key: value:
|
|
|
|
let
|
|
|
|
value' = if isBool value then
|
|
|
|
(if value then "True" else "False")
|
|
|
|
else
|
|
|
|
toString value;
|
|
|
|
in "${key} = ${value'}";
|
|
|
|
};
|
|
|
|
|
|
|
|
mpdris2Conf = {
|
|
|
|
Connection = {
|
|
|
|
host = cfg.mpd.host;
|
|
|
|
port = cfg.mpd.port;
|
|
|
|
music_dir = cfg.mpd.musicDirectory;
|
2023-01-10 09:35:00 +00:00
|
|
|
} // optionalAttrs (cfg.mpd.password != null) {
|
|
|
|
password = cfg.mpd.password;
|
2020-10-12 00:22:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Bling = {
|
|
|
|
notify = cfg.notifications;
|
|
|
|
mmkeys = cfg.multimediaKeys;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.pjones ];
|
|
|
|
|
|
|
|
options.services.mpdris2 = {
|
|
|
|
enable = mkEnableOption "mpDris2 the MPD to MPRIS2 bridge";
|
|
|
|
notifications = mkEnableOption "song change notifications";
|
|
|
|
multimediaKeys = mkEnableOption "multimedia key support";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.mpdris2;
|
2021-11-04 16:42:44 +00:00
|
|
|
defaultText = literalExpression "pkgs.mpdris2";
|
2020-10-12 00:22:58 +00:00
|
|
|
description = "The mpDris2 package to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
mpd = {
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.services.mpd.network.listenAddress;
|
|
|
|
defaultText = "config.services.mpd.network.listenAddress";
|
|
|
|
example = "192.168.1.1";
|
|
|
|
description = "The address where MPD is listening for connections.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = config.services.mpd.network.port;
|
|
|
|
defaultText = "config.services.mpd.network.port";
|
|
|
|
description = ''
|
|
|
|
The port number where MPD is listening for connections.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
musicDirectory = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = config.services.mpd.musicDirectory;
|
|
|
|
defaultText = "config.services.mpd.musicDirectory";
|
|
|
|
description = ''
|
|
|
|
If set, mpDris2 will use this directory to access music artwork.
|
|
|
|
'';
|
|
|
|
};
|
2023-01-10 09:35:00 +00:00
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The password to connect to MPD.
|
|
|
|
'';
|
|
|
|
};
|
2020-10-12 00:22:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-11-04 16:42:44 +00:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.mpdris2" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
2020-10-12 00:22:58 +00:00
|
|
|
|
|
|
|
xdg.configFile."mpDris2/mpDris2.conf".text = toIni mpdris2Conf;
|
|
|
|
|
|
|
|
systemd.user.services.mpdris2 = {
|
|
|
|
Install = { WantedBy = [ "default.target" ]; };
|
|
|
|
|
|
|
|
Unit = {
|
|
|
|
Description = "MPRIS 2 support for MPD";
|
|
|
|
After = [ "mpd.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "5s";
|
|
|
|
ExecStart = "${cfg.package}/bin/mpDris2";
|
|
|
|
BusName = "org.mpris.MediaPlayer2.mpd";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|