From 3aeefa9db252ecf3abf4d8aab20cca90e63c70f4 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 6 Feb 2026 23:11:11 +0000 Subject: [PATCH] mpdris2-rs: add module --- .github/labeler.yml | 1 + .../misc/news/2026/02/2026-02-06_21-46-14.nix | 10 ++ modules/services/mpdris2-rs.nix | 129 ++++++++++++++++++ .../mpdris2-rs/basic-configuration.nix | 10 ++ .../mpdris2-rs/basic-configuration.service | 12 ++ .../mpdris2-rs/custom-notifications.nix | 17 +++ .../mpdris2-rs/custom-notifications.service | 12 ++ tests/modules/services/mpdris2-rs/default.nix | 6 + 8 files changed, 197 insertions(+) create mode 100644 modules/misc/news/2026/02/2026-02-06_21-46-14.nix create mode 100644 modules/services/mpdris2-rs.nix create mode 100644 tests/modules/services/mpdris2-rs/basic-configuration.nix create mode 100644 tests/modules/services/mpdris2-rs/basic-configuration.service create mode 100644 tests/modules/services/mpdris2-rs/custom-notifications.nix create mode 100644 tests/modules/services/mpdris2-rs/custom-notifications.service create mode 100644 tests/modules/services/mpdris2-rs/default.nix diff --git a/.github/labeler.yml b/.github/labeler.yml index cc95a708..5573dea6 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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 diff --git a/modules/misc/news/2026/02/2026-02-06_21-46-14.nix b/modules/misc/news/2026/02/2026-02-06_21-46-14.nix new file mode 100644 index 00000000..86311611 --- /dev/null +++ b/modules/misc/news/2026/02/2026-02-06_21-46-14.nix @@ -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. + ''; +} diff --git a/modules/services/mpdris2-rs.nix b/modules/services/mpdris2-rs.nix new file mode 100644 index 00000000..e02bc8c0 --- /dev/null +++ b/modules/services/mpdris2-rs.nix @@ -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 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 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 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 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"; + }; + }; + }; +} diff --git a/tests/modules/services/mpdris2-rs/basic-configuration.nix b/tests/modules/services/mpdris2-rs/basic-configuration.nix new file mode 100644 index 00000000..a4dad2ff --- /dev/null +++ b/tests/modules/services/mpdris2-rs/basic-configuration.nix @@ -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} + ''; +} diff --git a/tests/modules/services/mpdris2-rs/basic-configuration.service b/tests/modules/services/mpdris2-rs/basic-configuration.service new file mode 100644 index 00000000..a1bd85ea --- /dev/null +++ b/tests/modules/services/mpdris2-rs/basic-configuration.service @@ -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 diff --git a/tests/modules/services/mpdris2-rs/custom-notifications.nix b/tests/modules/services/mpdris2-rs/custom-notifications.nix new file mode 100644 index 00000000..4e94f7e0 --- /dev/null +++ b/tests/modules/services/mpdris2-rs/custom-notifications.nix @@ -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} + ''; +} diff --git a/tests/modules/services/mpdris2-rs/custom-notifications.service b/tests/modules/services/mpdris2-rs/custom-notifications.service new file mode 100644 index 00000000..0e5e1e03 --- /dev/null +++ b/tests/modules/services/mpdris2-rs/custom-notifications.service @@ -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 diff --git a/tests/modules/services/mpdris2-rs/default.nix b/tests/modules/services/mpdris2-rs/default.nix new file mode 100644 index 00000000..2cc64cc0 --- /dev/null +++ b/tests/modules/services/mpdris2-rs/default.nix @@ -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; +}