party/colorchord: support multiple sound devices

This commit is contained in:
Simon Bruder 2021-12-29 21:56:30 +01:00
parent 4ba459520c
commit 8f4ce4f80d
No known key found for this signature in database
GPG key ID: 8D3C82F9F309F8EC

View file

@ -1,6 +1,6 @@
{ inputs, lib, pkgs, ... }:
let
devices = {
ledDevices = {
traverse = {
leds = 116;
host = "wled-Traverse";
@ -31,6 +31,19 @@ let
host = "wled-Bar";
};
};
soundDevices = {
sink = "alsa_output.usb-BurrBrown_from_Texas_Instruments_USB_AUDIO_CODEC-00.analog-stereo.monitor";
source = "alsa_input.usb-BurrBrown_from_Texas_Instruments_USB_AUDIO_CODEC-00.analog-stereo";
};
devicesProduct = lib.fold
(soundDevice: acc: acc // lib.mapAttrs'
(ledDevice: value: lib.nameValuePair "${ledDevice}-${soundDevice.name}" (value // {
source = soundDevice.id;
}))
ledDevices)
{ }
(lib.attrValues (lib.mapAttrs (n: v: { name = n; id = v; }) soundDevices));
in
{
environment.systemPackages = with pkgs; [
@ -49,7 +62,7 @@ in
# Audio input
amplify = 10
samplerate = 48000
devrecord = alsa_output.usb-BurrBrown_from_Texas_Instruments_USB_AUDIO_CODEC-00.analog-stereo.monitor
devrecord = ${config.source}
# Visualiser
cpu_autolimit = 1
@ -71,23 +84,29 @@ in
skipfirst = 0
'';
})
devices;
devicesProduct;
systemd.user.services."colorchord@" = {
partOf = [ "colorchord.target" ];
serviceConfig = {
ExecStart = ''
${pkgs.colorchord2}/bin/colorchord /etc/colorchord/%i.conf
'';
Restart = "always";
};
};
systemd.user.services = builtins.listToAttrs (map
(soundDevice: lib.nameValuePair
"colorchord-${soundDevice}@"
{
partOf = [ "colorchord-${soundDevice}.target" ];
serviceConfig = {
ExecStart = ''
${pkgs.colorchord2}/bin/colorchord /etc/colorchord/%i-${soundDevice}.conf
'';
Restart = "always";
};
})
(lib.attrNames soundDevices));
systemd.user.targets."colorchord" = {
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
wants = map (name: "colorchord@${name}.service") (lib.attrNames devices);
};
systemd.user.targets = builtins.listToAttrs (map
(soundDevice: lib.nameValuePair
"colorchord-${soundDevice}"
{
wants = map (ledDevice: "colorchord-${soundDevice}@${ledDevice}.service") (lib.attrNames ledDevices);
})
(lib.attrNames soundDevices));
nixpkgs.overlays = with inputs; [
sbruder-overlay.overlay