From 79def99252365ac4bf14a74382fb245f2ea987d4 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 11 Sep 2023 23:19:38 +0200 Subject: [PATCH] Enable Shairport Sync metadata and MQTT support --- config/hosts/audio/shairport-sync.conf | 25 +++++++++++++++++++++++++ config/hosts/audio/shairport-sync.nix | 6 ++++++ flake.nix | 14 ++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 config/hosts/audio/shairport-sync.conf diff --git a/config/hosts/audio/shairport-sync.conf b/config/hosts/audio/shairport-sync.conf new file mode 100644 index 0000000..8961505 --- /dev/null +++ b/config/hosts/audio/shairport-sync.conf @@ -0,0 +1,25 @@ +// Config for MQTT and metadata. +// For reference see: +// https://github.com/mikebrady/shairport-sync/blob/8c607e2d61ea5fde8ed0b48b2471a543840c31e6/scripts/shairport-sync.conf +// https://github.com/mikebrady/shairport-sync/blob/0f0f65b67649d4a25d06f13b56a6077a90b0f6cc/MQTT.md +metadata = +{ + enabled = "yes"; // set this to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe + include_cover_art = "yes"; // set to "yes" to get Shairport Sync to solicit cover art from the source and pass it via the pipe. You must also set "enabled" to "yes". + cover_art_cache_directory = "/tmp/shairport-sync/.cache/coverart"; // artwork will be stored in this directory if the dbus or MPRIS interfaces are enabled or if the MQTT client is in use. Set it to "" to prevent caching, which may be useful on some systems + pipe_name = "/tmp/shairport-sync-metadata"; + pipe_timeout = 5000; // wait for this number of milliseconds for a blocked pipe to unblock before giving up +}; + + +mqtt = +{ + enabled = "yes"; // set this to yes to enable the mqtt-metadata-service + hostname = "mqtt.ccchh.net"; // Hostname of the MQTT Broker + port = 1883; // Port on the MQTT Broker to connect to + topic = "audio"; //MQTT topic where this instance of shairport-sync should publish. If not set, the general.name value is used. +// publish_raw = "no"; //whether to publish all available metadata under the codes given in the 'metadata' docs. + publish_parsed = "yes"; //whether to publish a small (but useful) subset of metadata under human-understandable topics + publish_cover = "yes"; //whether to publish the cover over mqtt in binary form. This may lead to a bit of load on the broker +// enable_remote = "yes"; //whether to remote control via MQTT. RC is available under `topic`/remote. +}; diff --git a/config/hosts/audio/shairport-sync.nix b/config/hosts/audio/shairport-sync.nix index 5aac887..0407f79 100644 --- a/config/hosts/audio/shairport-sync.nix +++ b/config/hosts/audio/shairport-sync.nix @@ -5,4 +5,10 @@ openFirewall = true; arguments = "-v -o alsa -- -d plughw:1,0 -r 48000"; }; + + environment.etc.shairport-sync-config = { + enable = true; + source = ./shairport-sync.conf; + target = "shairport-sync.conf"; + }; } diff --git a/flake.nix b/flake.nix index bbea05f..1f9de33 100644 --- a/flake.nix +++ b/flake.nix @@ -13,12 +13,22 @@ }; }; - outputs = { nixpkgs, nixpkgs-unstable, nixos-generators, ... }: { + outputs = { nixpkgs, nixpkgs-unstable, nixos-generators, ... }: + let + # Shairport Sync with metadata and MQTT support. + shairportSyncExtendedNixpkgsUnstableOverlay = final: prev: { + shairport-sync = (prev.shairport-sync.override { enableMetadata = true; }).overrideAttrs (finalAttr: previousAttr: { + # See: https://github.com/mikebrady/shairport-sync/blob/e78a88b64adfe7b5f88fd6faedf55c57445bb240/CONFIGURATION%20FLAGS.md + configureFlags = previousAttr.configureFlags ++ [ "--with-mqtt-client" ]; + buildInputs = previousAttr.buildInputs ++ [ final.mosquitto ]; + }); + }; + in { colmena = { meta = { nixpkgs = nixpkgs.legacyPackages."x86_64-linux"; nodeNixpkgs = { - audio = nixpkgs-unstable.legacyPackages."x86_64-linux"; + audio = nixpkgs-unstable.legacyPackages."x86_64-linux".extend shairportSyncExtendedNixpkgsUnstableOverlay; }; };