1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-05 02:39:45 +01:00
home-manager/modules/services/mpdris2.nix

113 lines
2.9 KiB
Nix
Raw Normal View History

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