From c23cd959e322c684fc42eb5a3da7da2b55e1178d Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 2 Oct 2025 11:50:06 +0200 Subject: [PATCH] Add pipewire to iron --- hosts/iron/services/snapcast/alsa.nix | 6 ---- .../iron/services/snapcast/bluetooth-sink.nix | 24 +++++++++++---- hosts/iron/services/snapcast/default.nix | 15 +++++++++- hosts/iron/services/snapcast/ledfx.nix | 29 +++++++++++++++++-- hosts/iron/services/snapcast/snapclient.nix | 5 ++-- 5 files changed, 61 insertions(+), 18 deletions(-) delete mode 100644 hosts/iron/services/snapcast/alsa.nix diff --git a/hosts/iron/services/snapcast/alsa.nix b/hosts/iron/services/snapcast/alsa.nix deleted file mode 100644 index 1b8566e..0000000 --- a/hosts/iron/services/snapcast/alsa.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - boot.kernelModules = [ "snd-aloop" ]; - boot.extraModprobeConfig = '' - options snd-aloop id=ledfx,bluetooth enable=1,1 pcm_substreams=2,2 - ''; -} diff --git a/hosts/iron/services/snapcast/bluetooth-sink.nix b/hosts/iron/services/snapcast/bluetooth-sink.nix index 38cf8e3..43db142 100644 --- a/hosts/iron/services/snapcast/bluetooth-sink.nix +++ b/hosts/iron/services/snapcast/bluetooth-sink.nix @@ -1,7 +1,11 @@ { pkgs, ... }: { environment.systemPackages = with pkgs; [ - bluez-alsa + #bluez-alsa + bluez + bluez-tools + pipewire + wireplumber ]; hardware.bluetooth = { @@ -18,11 +22,17 @@ FastConnectable = "true"; # Allow repairing of existing devices JustWorksRepairing = "always"; + # to show battery state + Experimental = true; }; }; }; - services.blueman.enable = true; + services = { + blueman.enable = true; + ofono.enable = true; + upower.enable = true; + }; systemd.services = { bluetooth-auto-pair = { @@ -45,7 +55,8 @@ Restart = "on-failure"; }; }; - bluealsa-aplay = { + /* + bluealsa-aplay = { wantedBy = [ "multi-user.target" ]; serviceConfig = { DynamicUser = true; @@ -54,14 +65,15 @@ Restart = "on-failure"; SupplementaryGroups = [ "audio" ]; }; - }; - bluealsa-a2dp = { + }; + bluealsa-a2dp = { wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "simple"; ExecStart = "${pkgs.bluez-alsa}/bin/bluealsa -p a2dp-sink"; Restart = "on-failure"; }; - }; + }; + */ }; } diff --git a/hosts/iron/services/snapcast/default.nix b/hosts/iron/services/snapcast/default.nix index 803531e..496bb63 100644 --- a/hosts/iron/services/snapcast/default.nix +++ b/hosts/iron/services/snapcast/default.nix @@ -1,10 +1,23 @@ +{ pkgs, ... }: + { imports = [ - ./alsa.nix ./bluetooth-sink.nix ./ledfx.nix ./mopidy.nix ./snapclient.nix ./snapserver.nix ]; + + services.pipewire = { + enable = true; + systemWide = true; + audio.enable = true; + pulse.enable = true; + alsa.enable = true; + }; + + environment.systemPackages = [ pkgs.pulseaudio ]; + + users.users.jalr.extraGroups = [ "pipewire" ]; } diff --git a/hosts/iron/services/snapcast/ledfx.nix b/hosts/iron/services/snapcast/ledfx.nix index 4a4a3d6..d7db19d 100644 --- a/hosts/iron/services/snapcast/ledfx.nix +++ b/hosts/iron/services/snapcast/ledfx.nix @@ -7,6 +7,29 @@ in 8888 ]; + + services.pipewire.extraConfig.pipewire."10-ledfx-loop" = { + "context.modules" = [ + { + name = "libpipewire-module-loopback"; + args = { + "audio.position" = [ "FL,FR" ]; + "capture.props" = { + "media.class" = "Audio/Sink"; + "node.name" = "ledfx.input"; + "node.description" = "ledfx capture"; + }; + "playback.props" = { + "media.class" = "Audio/Source"; + "node.name" = "ledfx.output"; + "node.passive" = true; + }; + }; + } + ]; + }; + + systemd.services.snapclient-ledfx = { enable = true; description = "Snapcast client"; @@ -15,8 +38,8 @@ in wantedBy = [ "multi-user.target" ]; serviceConfig = { DynamicUser = "yes"; - ExecStart = "${pkgs.snapcast}/bin/snapclient --host 127.0.0.1 --hostID ledfx -i 2 --player alsa -s ledfx"; - Group = "audio"; + ExecStart = "${pkgs.snapcast}/bin/snapclient --host 127.0.0.1 --hostID ledfx -i 2 --player pulse -s ledfx.input"; + Group = "pipewire"; NoNewPrivileges = true; ProtectControlGroups = true; ProtectHome = true; @@ -37,7 +60,7 @@ in serviceConfig = { DynamicUser = "yes"; ExecStart = "${pkgs.ledfx}/bin/ledfx --host 0.0.0.0 -p 8888 -c %S/ledfx"; - Group = "audio"; + Group = "pipewire"; NoNewPrivileges = true; ProtectControlGroups = true; ProtectHome = true; diff --git a/hosts/iron/services/snapcast/snapclient.nix b/hosts/iron/services/snapcast/snapclient.nix index 27bb202..b0c4687 100644 --- a/hosts/iron/services/snapcast/snapclient.nix +++ b/hosts/iron/services/snapcast/snapclient.nix @@ -7,10 +7,11 @@ wants = [ "network.target" "sound.target" ]; after = [ "network.target" "sound.target" ]; wantedBy = [ "multi-user.target" ]; + environment.PULSE_SERVER = "unix:/run/pulse/native"; serviceConfig = { DynamicUser = "yes"; - ExecStart = "${pkgs.snapcast}/bin/snapclient --host 127.0.0.1 -s DAC"; - Group = "audio"; + ExecStart = "${pkgs.snapcast}/bin/snapclient --host 127.0.0.1 --player pulse -s alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00.analog-stereo"; + Group = "pipewire"; NoNewPrivileges = true; ProtectControlGroups = true; ProtectHome = true;