mpdris2-rs: add module

This commit is contained in:
Matthias Ahouansou 2026-02-06 23:11:11 +00:00 committed by Austin Horstman
parent 40955dc50a
commit 3aeefa9db2
8 changed files with 197 additions and 0 deletions

1
.github/labeler.yml vendored
View file

@ -19,6 +19,7 @@
- modules/services/mpd-mpris.nix
- modules/services/mpd.nix
- modules/services/mpdris2.nix
- modules/services/mpdris2-rs.nix
- modules/services/mpdscribble.nix
- modules/services/mpris-proxy.nix
- modules/services/pasystray.nix

View file

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
time = "2026-02-06T21:46:14+00:00";
condition = pkgs.stdenv.hostPlatform.isLinux;
message = ''
A new module is available: `services.mpdris2-rs`
Adds a module for mpdris2-rs, a lightweight implementation of the MPD to D-Bus bridge.
'';
}

View file

@ -0,0 +1,129 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.mpdris2-rs;
in
{
meta.maintainers = [ lib.maintainers.Kladki ];
options.services.mpdris2-rs = {
enable = lib.mkEnableOption "mpdris2-rs, A lightweight implementation of MPD to D-Bus bridge";
host = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "192.168.1.1";
description = ''
hostname + port, or UNIX socket path of MPD server, similar to what `mpc` takes
- if not configured, `MPD_HOST` will be used
- if `MPD_HOST` is not set either, `localhost:6600` is the default
- UNIX socket path has to be absolute
- Abstract sockets are supported on Linux (socket path that starts with `@`, e.g., `@mpd_socket`)
'';
};
notifications = {
enable = lib.mkEnableOption "song change notifications";
timeout = lib.mkOption {
type = with lib.types; nullOr float;
default = null;
example = 10.0;
description = "notification timeout (default 5 secs)";
};
summary = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "%artist% - %album%";
description = ''
Templating for the notification summary.
See <https://github.com/szclsya/mpdris2-rs?tab=readme-ov-file#configuration> for available variables.
'';
};
summaryPaused = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "%artist% - %album%";
description = ''
Templating for the notification summary (when paused).
See <https://github.com/szclsya/mpdris2-rs?tab=readme-ov-file#configuration> for available variables.
'';
};
body = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "%title% (%elapsed%/%duration%)";
description = ''
Templating for the notification body.
See <https://github.com/szclsya/mpdris2-rs?tab=readme-ov-file#configuration> for available variables.
'';
};
bodyPaused = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "%title% (%elapsed%/%duration%)";
description = ''
Templating for the notification body (when paused).
See <https://github.com/szclsya/mpdris2-rs?tab=readme-ov-file#configuration> for available variables.
'';
};
};
package = lib.mkPackageOption pkgs "mpdris2-rs" { };
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.mpdris2-rs" pkgs lib.platforms.linux)
];
systemd.user.services.mpdris2-rs = {
Install = {
WantedBy = [ "default.target" ];
};
Unit = {
Description = "Music Player Daemon D-Bus Bridge";
After = [ "mpd.service" ];
};
Service = {
Type = "dbus";
Restart = "on-failure";
ExecStart =
let
optionFormat = optionName: {
option = "--${optionName}";
sep = null;
explicitBool = false;
};
args = lib.cli.toCommandLineShell optionFormat {
host = cfg.host;
no-notification = !cfg.notifications.enable;
notification-timeout = cfg.notifications.timeout;
notification-summary = cfg.notifications.summary;
notification-summary-paused = cfg.notifications.summaryPaused;
notification-body = cfg.notifications.body;
notification-body-paused = cfg.notifications.bodyPaused;
};
in
"${lib.getExe cfg.package} ${args}";
BusName = "org.mpris.MediaPlayer2.mpd";
};
};
};
}

View file

@ -0,0 +1,10 @@
{
services.mpdris2-rs = {
enable = true;
};
nmt.script = ''
serviceFile=home-files/.config/systemd/user/mpdris2-rs.service
assertFileContent "$serviceFile" ${./basic-configuration.service}
'';
}

View file

@ -0,0 +1,12 @@
[Install]
WantedBy=default.target
[Service]
BusName=org.mpris.MediaPlayer2.mpd
ExecStart=@mpdris2-rs@/bin/mpdris2-rs --no-notification
Restart=on-failure
Type=dbus
[Unit]
After=mpd.service
Description=Music Player Daemon D-Bus Bridge

View file

@ -0,0 +1,17 @@
{
services.mpdris2-rs = {
enable = true;
notifications = {
enable = true;
summary = "%artist% - %album%";
summaryPaused = "%artist% - %album% (paused)";
body = "%title% (%elapsed%/%duration%)";
bodyPaused = "%title% (%elapsed%/%duration%) (paused)";
};
};
nmt.script = ''
serviceFile=home-files/.config/systemd/user/mpdris2-rs.service
assertFileContent "$serviceFile" ${./custom-notifications.service}
'';
}

View file

@ -0,0 +1,12 @@
[Install]
WantedBy=default.target
[Service]
BusName=org.mpris.MediaPlayer2.mpd
ExecStart=@mpdris2-rs@/bin/mpdris2-rs --notification-body '%title% (%elapsed%/%duration%)' --notification-body-paused '%title% (%elapsed%/%duration%) (paused)' --notification-summary '%artist% - %album%' --notification-summary-paused '%artist% - %album% (paused)'
Restart=on-failure
Type=dbus
[Unit]
After=mpd.service
Description=Music Player Daemon D-Bus Bridge

View file

@ -0,0 +1,6 @@
{ lib, pkgs, ... }:
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
mpdris2-rs-basic-configuration = ./basic-configuration.nix;
mpdris2-rs-custom-notifications = ./custom-notifications.nix;
}