From e74bdefc730ae253a20f0333e6dcfd73bda4b365 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Tue, 25 Jan 2022 12:15:56 +0000 Subject: [PATCH] work on sound broadcasting infra --- home/bluetooth/bluetooth.nix | 4 +-- hosts/hetzner-vm/services/mpd.nix | 25 +++++++++++++------ hosts/lappy/lappy.nix | 2 +- hosts/lappy/profiles/mpd.nix | 12 ++++----- outputs.nix | 1 + profiles/sound/pulseaudio/default.nix | 12 --------- profiles/sound/pulseaudio/pulse-bluetooth.nix | 11 ++++++++ .../pulse-recv-native-localhost.nix | 7 ++++++ profiles/sound/pulseaudio/pulse-recv-rtp.nix | 7 ++++++ .../sound/pulseaudio/pulse-systemwide.nix | 7 ++++++ profiles/sound/pulseaudio/pulse.nix | 7 ++++++ 11 files changed, 65 insertions(+), 30 deletions(-) delete mode 100644 profiles/sound/pulseaudio/default.nix create mode 100644 profiles/sound/pulseaudio/pulse-bluetooth.nix create mode 100644 profiles/sound/pulseaudio/pulse-recv-native-localhost.nix create mode 100644 profiles/sound/pulseaudio/pulse-recv-rtp.nix create mode 100644 profiles/sound/pulseaudio/pulse-systemwide.nix create mode 100644 profiles/sound/pulseaudio/pulse.nix diff --git a/home/bluetooth/bluetooth.nix b/home/bluetooth/bluetooth.nix index 6c524e2..8218b29 100644 --- a/home/bluetooth/bluetooth.nix +++ b/home/bluetooth/bluetooth.nix @@ -1,6 +1,4 @@ -{ config, lib, ... }: - -{ +{ config, lib, ... }: { services.blueman-applet.enable = true; services.mpris-proxy.enable = true; } diff --git a/hosts/hetzner-vm/services/mpd.nix b/hosts/hetzner-vm/services/mpd.nix index f47c6ac..55737a9 100644 --- a/hosts/hetzner-vm/services/mpd.nix +++ b/hosts/hetzner-vm/services/mpd.nix @@ -1,12 +1,21 @@ -{ pkgs, lib, ... }: { - environment.systemPackages = with pkgs; [ mpc_cli ]; +{ pkgs, lib, tree, ... }: { + imports = with tree; [ + # systemwide pulseaudio w/ recv native localhost + # to broadcast to all speakers over rtp + profiles.sound.pulseaudio.pulse-systemwide + profiles.sound.pulseaudio.pulse-recv-native-localhost + ]; - sound.enable = true; hardware.pulseaudio = { - systemWide = true; - enable = true; + extraConfig = '' + # laptop + load-module module-null-sink sink_name=rtp-lappy sink_properties="device.description='Laptop Output'" + load-module module-rtp-send source=rtp-lappy.monitor destination_ip=100.115.10.34 + ''; }; + environment.systemPackages = with pkgs; [ mpc_cli ]; + services.mpd = { enable = true; network.listenAddress = "0.0.0.0"; @@ -33,12 +42,14 @@ } audio_output { type "pulse" - name "Out" - server "lappy.tailscale-internal.genderfucked.monster" + name "Lappy Out" + target "rtp-lappy" + server "127.0.0.1" } ''; }; + systemd.services.mpd.serviceConfig.After = ["pulseaudio.service"]; systemd.services.mpd.serviceConfig.StateDirectory = [ "/mpd" ]; services.nginx.virtualHosts."stream.owo.monster" = { diff --git a/hosts/lappy/lappy.nix b/hosts/lappy/lappy.nix index 50d0913..f1dc187 100644 --- a/hosts/lappy/lappy.nix +++ b/hosts/lappy/lappy.nix @@ -18,7 +18,7 @@ profiles.connectivity.network_manager profiles.connectivity.ios - profiles.sound.pulseaudio + profiles.sound.pulseaudio.pulse profiles.gui profiles.gui.environments.sway diff --git a/hosts/lappy/profiles/mpd.nix b/hosts/lappy/profiles/mpd.nix index b0d896d..1032376 100644 --- a/hosts/lappy/profiles/mpd.nix +++ b/hosts/lappy/profiles/mpd.nix @@ -1,12 +1,10 @@ { pkgs, tree, ... }: { - imports = [ ./mpd-music-sync.nix ]; + imports = [ ./mpd-music-sync.nix ] ++ (with tree; [ + profiles.sound.pulseaudio.pulse-recv-native-localhost + profiles.sound.pulseaudio.pulse-recv-rtp + ]); - hardware.pulseaudio = { - extraConfig = - "load-module module-native-protocol-tcp auth-anonymous=1 auth-ip-acl=127.0.0.1;100.64.0.0/8"; - }; - - environment.systemPackages = with pkgs; [ mpc_cli ]; + environment.systemPackages = with pkgs; [ mpc_cli roc-toolkit ]; systemd.tmpfiles.rules = [ "d /var/lib/mpd 0755 mpd mpd -" diff --git a/outputs.nix b/outputs.nix index 9d49835..3cbedc3 100644 --- a/outputs.nix +++ b/outputs.nix @@ -10,6 +10,7 @@ let "hosts/*/profiles".functor.enable = true; "profiles/*".functor.enable = true; "profiles/sound/*".functor.enable = true; + "profiles/sound/pulseaudio/*".functor.enable = true; "profiles/connectivity/*".functor.enable = true; "profiles/gaming/*".functor.enable = true; "profiles/gui/environments/*".functor.enable = true; diff --git a/profiles/sound/pulseaudio/default.nix b/profiles/sound/pulseaudio/default.nix deleted file mode 100644 index be4f0ef..0000000 --- a/profiles/sound/pulseaudio/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ config, pkgs, ... }: { - sound.enable = true; - nixpkgs.config.pulseaudio = true; - hardware.pulseaudio = { - enable = true; - #support32Bit = true; - extraModules = with pkgs; [ pkgs.pulseaudio-modules-bt ]; - package = pkgs.pulseaudioFull; - extraConfig = "\n load-module module-switch-on-connect\n "; - }; - environment.systemPackages = with pkgs; [ pavucontrol ]; -} diff --git a/profiles/sound/pulseaudio/pulse-bluetooth.nix b/profiles/sound/pulseaudio/pulse-bluetooth.nix new file mode 100644 index 0000000..060628a --- /dev/null +++ b/profiles/sound/pulseaudio/pulse-bluetooth.nix @@ -0,0 +1,11 @@ +{ pkgs, tree, lib, ... }: { + imports = with tree; [ + profiles.connectivity.bluetooth + ]; + + hardware.pulseaudio = { + extraModules = with pkgs; [ pkgs.pulseaudio-modules-bt ]; + package = lib.mkForce pkgs.pulseaudioFull; + extraConfig = "load-module module-switch-on-connect"; + }; +} diff --git a/profiles/sound/pulseaudio/pulse-recv-native-localhost.nix b/profiles/sound/pulseaudio/pulse-recv-native-localhost.nix new file mode 100644 index 0000000..63f20a7 --- /dev/null +++ b/profiles/sound/pulseaudio/pulse-recv-native-localhost.nix @@ -0,0 +1,7 @@ +{ ... }: { + hardware.pulseaudio = { + extraConfig = '' + load-module module-native-protocol-tcp auth-anonymous=1 auth-ip-acl=127.0.0.1; + ''; + }; +} diff --git a/profiles/sound/pulseaudio/pulse-recv-rtp.nix b/profiles/sound/pulseaudio/pulse-recv-rtp.nix new file mode 100644 index 0000000..a4adde2 --- /dev/null +++ b/profiles/sound/pulseaudio/pulse-recv-rtp.nix @@ -0,0 +1,7 @@ +{ ... }: { + hardware.pulseaudio = { + extraConfig = '' + load-module module-rtp-recv latency_msec=50 sap_address=0.0.0.0 + ''; + }; +} diff --git a/profiles/sound/pulseaudio/pulse-systemwide.nix b/profiles/sound/pulseaudio/pulse-systemwide.nix new file mode 100644 index 0000000..7fa3f6e --- /dev/null +++ b/profiles/sound/pulseaudio/pulse-systemwide.nix @@ -0,0 +1,7 @@ +{tree, ...}: { + imports = with tree; [ profiles.sound.pulseaudio.pulse ]; + hardware.pulseaudio = { + systemWide = true; + enable = true; + }; +} \ No newline at end of file diff --git a/profiles/sound/pulseaudio/pulse.nix b/profiles/sound/pulseaudio/pulse.nix new file mode 100644 index 0000000..50e2135 --- /dev/null +++ b/profiles/sound/pulseaudio/pulse.nix @@ -0,0 +1,7 @@ +{ config, pkgs, ... }: { + sound.enable = true; + nixpkgs.config.pulseaudio = true; + hardware.pulseaudio = { + enable = true; + }; +}