Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions modules/misc/news/2026/02/2026-02-22_09-45-54.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs, ... }:
{
time = "2026-02-22T09:45:54+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.
'';
}
129 changes: 129 additions & 0 deletions modules/services/mpdris2-rs.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
};
}
10 changes: 10 additions & 0 deletions tests/modules/services/mpdris2-rs/basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -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}
'';
}
12 changes: 12 additions & 0 deletions tests/modules/services/mpdris2-rs/basic-configuration.service
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/modules/services/mpdris2-rs/custom-notifications.nix
Original file line number Diff line number Diff line change
@@ -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}
'';
}
12 changes: 12 additions & 0 deletions tests/modules/services/mpdris2-rs/custom-notifications.service
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/modules/services/mpdris2-rs/default.nix
Original file line number Diff line number Diff line change
@@ -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;
}
Loading