nixfiles/hosts/raspberry/services/mpd-recv.nix
ChaotiCryptidz 9a3493bf0c cursed
2022-01-26 23:05:24 +00:00

75 lines
2.2 KiB
Nix

{ tree, pkgs, ... }:
let
process-media-controls = pkgs.writeText "process-media-controls" ''
import asyncio
import os
from evdev import InputDevice, categorize, ecodes
dev = InputDevice('/dev/input/event0')
async def scanner(dev):
async for ev in dev.async_read_loop():
if ev.type == ecodes.EV_KEY:
if ev.code in [ecodes.KEY_PLAYCD, ecodes.KEY_PAUSECD] and ev.value == 0:
print("Play/Pause Pressed")
os.system("pactl set-sink-mute @DEFAULT_SINK@ toggle")
loop = asyncio.get_event_loop()
loop.run_until_complete(scanner(dev))
'';
in {
imports = with tree; [
profiles.connectivity.bluetooth
profiles.sound.pulseaudio.pulse
profiles.sound.pulseaudio.pulse-systemwide
profiles.sound.pulseaudio.pulse-bluetooth
profiles.sound.pulseaudio.pulse-recv-native-localhost
];
systemd = {
services.roc-recv = {
requires = [ "network.target" "pulseaudio.service" ];
after = [ "network.target" "pulseaudio.service" ];
wantedBy = [ "multi-user.target" ];
script = ''
PULSE_SERVER=127.0.0.1 ${pkgs.roc-toolkit-patched}/bin/roc-recv --source "rtp:0.0.0.0:10001"
'';
serviceConfig = { Restart = "always"; };
};
services.process-media-controls = {
requires = [ "network.target" "pulseaudio.service" ];
after = [ "network.target" "pulseaudio.service" ];
wantedBy = [ "multi-user.target" ];
path = [ pkgs.pulseaudio ];
script = let
python = pkgs.python39.withPackages
(ps: with ps; [ pkgs.python39Packages.evdev ]);
in ''
(${python.interpreter} ${process-media-controls}) || true
'';
serviceConfig = {
Restart = "always";
StartLimitAction = "none";
};
};
timers.bt-autoconnect = {
wantedBy = [ "timers.target" ];
partOf = [ "bt-autoconnect.service" ];
timerConfig.OnCalendar = "minutely";
};
services.bt-autoconnect = {
serviceConfig.Type = "oneshot";
script = ''
${pkgs.bluez}/bin/bluetoothctl connect 3E:39:E7:B2:86:29 || true
'';
};
};
hardware.pulseaudio.extraConfig = ''
set-default-sink bluez_card.3E_39_E7_B2_86_29
'';
}