Add bluetooth sink

This commit is contained in:
Jakob Lechner 2024-12-16 03:15:58 +01:00
parent d89a84cb9e
commit 84e7d76f14
8 changed files with 107 additions and 18 deletions

View file

@ -7,18 +7,15 @@
./esphome
./home-assistant.nix
./jellyfin.nix
./ledfx.nix
./mail.nix
./matrix.nix
./mopidy.nix
./navidrome.nix
./nginx.nix
./ntp.nix
./public-ip-tunnel.nix
./radicale.nix
./remarkable.nix
./snapclient.nix
./snapserver.nix
./snapcast
./sturzbach.nix
./tts.nix
./unifi-controller.nix

View file

@ -0,0 +1,6 @@
{
boot.kernelModules = [ "snd-aloop" ];
boot.extraModprobeConfig = ''
options snd-aloop id=ledfx,bluetooth enable=1,1 pcm_substreams=2,2
'';
}

View file

@ -0,0 +1,77 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
bluez-alsa
];
hardware.bluetooth = {
enable = true;
settings = {
General = {
Enable = "Source,Sink,Media,Socket";
Class = "0x00041C";
# Pairing always on
AlwaysPairable = "true";
# Don't disable discoverability after timeout
DiscoverableTimeout = "0";
# Faster but uses more power
FastConnectable = "true";
# Allow repairing of existing devices
JustWorksRepairing = "always";
};
};
};
services.blueman.enable = true;
systemd.services.bluetooth-auto-pair = {
wantedBy = [
"bluetooth.service"
];
after = [
"bluetooth.service"
];
bindsTo = [
"bluetooth.service"
];
serviceConfig = {
Type = "simple";
ExecStart = pkgs.writeShellScript "exec-start" ''
${pkgs.bluez}/bin/bluetoothctl <<EOF
discoverable on
pairable on
EOF
${pkgs.coreutils}/bin/yes | ${pkgs.bluez-tools}/bin/bt-agent -c NoInputNoOutput
'';
ExecStop = pkgs.writeShellScript "exec-stop" ''
kill -s SIGINT $MAINPID
'';
Restart = "on-failure";
};
};
systemd.services.bluealsa-aplay = {
wantedBy = [
"multi-user.target"
];
serviceConfig = {
DynamicUser = true;
Type = "simple";
ExecStart = "${pkgs.bluez-alsa}/bin/bluealsa-aplay --profile-a2dp --pcm=default:CARD=bluetooth 00:00:00:00:00:00";
Restart = "on-failure";
SupplementaryGroups = [ "audio" ];
};
};
systemd.services.bluealsa-a2dp = {
wantedBy = [
"multi-user.target"
];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.bluez-alsa}/bin/bluealsa -p a2dp-sink";
Restart = "on-failure";
};
};
}

View file

@ -0,0 +1,10 @@
{
imports = [
./alsa.nix
./bluetooth-sink.nix
./ledfx.nix
./mopidy.nix
./snapclient.nix
./snapserver.nix
];
}

View file

@ -1,6 +1,6 @@
args@{ lib, pkgs, config, custom-utils, ... }:
let
interfaces = import ../interfaces.nix;
interfaces = import ../../interfaces.nix;
in
{
networking.firewall.interfaces."${interfaces.lan}".allowedTCPPorts = [
@ -49,9 +49,4 @@ in
StateDirectoryMode = "0755";
};
};
boot.kernelModules = [ "snd-aloop" ];
boot.extraModprobeConfig = ''
options snd-aloop id=ledfx enable=1 pcm_substreams=1
'';
}

View file

@ -1,6 +1,6 @@
args@{ lib, pkgs, config, custom-utils, ... }:
let
interfaces = import ../interfaces.nix;
interfaces = import ../../interfaces.nix;
mopidyConfig = {
audio.output = "audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/run/snapserver/mopidy.fifo";
file.enabled = false;

View file

@ -1,7 +1,7 @@
args@{ lib, pkgs, config, custom-utils, ... }:
let
ports = import ../ports.nix args;
interfaces = import ../interfaces.nix;
ports = import ../../ports.nix args;
interfaces = import ../../interfaces.nix;
in
{
services.snapserver = {
@ -9,7 +9,7 @@ in
streams = {
default = {
type = "meta";
location = "meta:///hass/airplay/mopidy";
location = "meta:///hass/bluetooth/airplay/mopidy";
};
mopidy = {
type = "pipe";
@ -19,6 +19,13 @@ in
type = "pipe";
location = "/run/snapserver/hass.fifo";
};
bluetooth = {
location = "";
type = "alsa";
query = {
device = "hw:bluetooth,1";
};
};
airplay = {
type = "airplay";
location = lib.getExe' pkgs.shairport-sync "shairport-sync";
@ -29,10 +36,7 @@ in
};
};
#systemd.services.snapserver = {
#requires = [config.systemd.services.mopidy.name];
#after = [config.systemd.services.mopidy.name];
#};
systemd.services.snapserver.serviceConfig.SupplementaryGroups = [ "audio" ];
services.home-assistant.config.media_player = [
{