From f07510e2b63075a5e334e603f666c5c5838563ce Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 20 Feb 2019 08:38:40 -0700 Subject: [PATCH] mpdris2: add module --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/services/mpdris2.nix | 101 +++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 modules/services/mpdris2.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 2d18442ff..9684c3a70 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -991,6 +991,13 @@ in A new module is available: 'programs.keychain'. ''; } + + { + time = "2019-02-24T00:32:23+00:00"; + message = '' + A new service is available: 'services.mpdris2'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 85ee166a7..16517ccfc 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -96,6 +96,7 @@ let (loadModule ./services/keybase.nix { }) (loadModule ./services/mbsync.nix { }) (loadModule ./services/mpd.nix { }) + (loadModule ./services/mpdris2.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/network-manager-applet.nix { }) (loadModule ./services/nextcloud-client.nix { }) (loadModule ./services/owncloud-client.nix { }) diff --git a/modules/services/mpdris2.nix b/modules/services/mpdris2.nix new file mode 100644 index 000000000..14c890230 --- /dev/null +++ b/modules/services/mpdris2.nix @@ -0,0 +1,101 @@ +{ 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; + }; + + 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; + defaultText = "pkgs.mpdris2"; + 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.ints.positive; + 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. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = config.services.mpd.enable; + message = "The mpdris2 module requires 'services.mpd.enable = true'."; + } + ]; + + xdg.configFile."mpDris2/mpDris2.conf".text = toIni mpdris2Conf; + + systemd.user.services.mpdris2 = { + Unit = { + Description = "MPRIS 2 support for MPD"; + After = [ "graphical-session-pre.target" "mpd.service" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/mpDris2"; + }; + }; + }; +}