nixos-configuration/hosts/iron/services/snapcast/bluetooth-sink.nix
2025-04-16 22:54:28 +02:00

67 lines
1.8 KiB
Nix

{ 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";
};
};
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" ];
};
};
bluealsa-a2dp = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.bluez-alsa}/bin/bluealsa -p a2dp-sink";
Restart = "on-failure";
};
};
};
}