From ef7c53f15b80ec6cfe6cf81769717a0d64d5cce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 2 Jan 2024 10:35:03 +0100 Subject: [PATCH] feat(pipewire): try to do some pulseaudio networking stuff --- configs/default.nix | 1 + configs/sound.nix | 31 +++++++++++-------------------- systems/zaatar/configuration.nix | 2 +- systems/zaatar/kiosk.nix | 2 +- systems/zaatar/mpd.nix | 4 +++- systems/zaatar/pulseaudio.nix | 17 ----------------- systems/zaatar/spotifyd.nix | 8 ++++++-- 7 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 systems/zaatar/pulseaudio.nix diff --git a/configs/default.nix b/configs/default.nix index 040ed7b..4006fec 100644 --- a/configs/default.nix +++ b/configs/default.nix @@ -86,6 +86,7 @@ in { hashedPasswordFile = config.age.secrets.kfm-password.path; isNormalUser = true; uid = 1000; + extraGroups = ["pipewire" "audio"]; }; age.secrets = { diff --git a/configs/sound.nix b/configs/sound.nix index 22faabe..3fa9a49 100644 --- a/configs/sound.nix +++ b/configs/sound.nix @@ -1,9 +1,6 @@ {pkgs, ...}: { sound.enable = true; - # realtime audio - security.rtkit.enable = true; - services.pipewire = { enable = true; alsa = { @@ -16,25 +13,19 @@ systemd.user.services.pipewire-pulse.path = [pkgs.pulseaudio]; - hardware.pulseaudio = { - enable = false; - package = pkgs.pulseaudioFull; - # copy server:/run/pulse/.config/pulse/cookie to client:~/.config/pulse/cookie to authenticate a client machine - zeroconf.discovery.enable = true; - extraConfig = '' - load-module ${ - toString [ - "module-tunnel-sink-new" - "server=zaatar.r" - "sink_name=zaatar" - "channels=2" - "rate=44100" - ] - } - ''; + services.avahi = { + enable = true; + publish.enable = true; + publish.userServices = true; }; - users.users.me.extraGroups = ["pipewire" "audio"]; + environment.etc."pipewire/pipewire-pulse.conf.d/50-network-party.conf".text = '' + context.exec = [ + { path = "pactl" args = "load-module module-native-protocol-tcp" } + { path = "pactl" args = "load-module module-zeroconf-discover" } + { path = "pactl" args = "load-module module-zeroconf-publish" } + ] + ''; environment.systemPackages = [ pkgs.pavucontrol diff --git a/systems/zaatar/configuration.nix b/systems/zaatar/configuration.nix index 17d1cdf..d2b5534 100644 --- a/systems/zaatar/configuration.nix +++ b/systems/zaatar/configuration.nix @@ -12,12 +12,12 @@ in { ./gaslight.nix ./kiosk.nix ./hardware-configuration.nix - ./pulseaudio.nix ./home-assistant.nix ./mpd.nix ./grocy.nix ./spotifyd.nix ../../configs/keyboard.nix + ../../configs/sound.nix ../../configs/monitoring.nix ../../configs/retiolum.nix ../../configs/printing.nix diff --git a/systems/zaatar/kiosk.nix b/systems/zaatar/kiosk.nix index fde2fb2..c8f57ab 100644 --- a/systems/zaatar/kiosk.nix +++ b/systems/zaatar/kiosk.nix @@ -7,7 +7,7 @@ users.extraUsers.kiosk = { isNormalUser = true; password = ""; - extraGroups = ["audio"]; + extraGroups = ["audio" "pipewire"]; }; # TODO https://github.com/cage-kiosk/cage/issues/138 services.cage = { diff --git a/systems/zaatar/mpd.nix b/systems/zaatar/mpd.nix index ad8524d..be090a9 100644 --- a/systems/zaatar/mpd.nix +++ b/systems/zaatar/mpd.nix @@ -36,6 +36,8 @@ in { }; }; + users.users.${config.services.mpd.user}.extraGroups = ["pipewire"]; + services.mpd = { enable = true; network.listenAddress = "0.0.0.0"; @@ -44,7 +46,7 @@ in { auto_update "yes" audio_output { - type "pulse" + type "pipewire" name "zaatar single room audio system" } ''; diff --git a/systems/zaatar/pulseaudio.nix b/systems/zaatar/pulseaudio.nix deleted file mode 100644 index 30d200b..0000000 --- a/systems/zaatar/pulseaudio.nix +++ /dev/null @@ -1,17 +0,0 @@ -{pkgs, ...}: { - sound.enable = true; - - environment.systemPackages = [pkgs.ncpamixer]; - - hardware.pulseaudio = { - package = pkgs.pulseaudioFull; - enable = true; - systemWide = true; - tcp = { - enable = true; - anonymousClients.allowedIpRanges = ["127.0.0.1" "10.243.2.0/24" "192.168.0.0/16"]; - }; - zeroconf.publish.enable = true; - }; - networking.firewall.allowedTCPPorts = [4713]; -} diff --git a/systems/zaatar/spotifyd.nix b/systems/zaatar/spotifyd.nix index 21e8ddc..55b6251 100644 --- a/systems/zaatar/spotifyd.nix +++ b/systems/zaatar/spotifyd.nix @@ -3,7 +3,10 @@ # mpris is a dbus service for controlling all music players with e.g. playerctl # I do not need this, because I only interact with the service via Spotify Connect # otherẃise it will pull in DBus which fails without X11 - spotifyd = pkgs.spotifyd.overrideAttrs {withMPris = false;}; + spotifyd = pkgs.spotifyd.overrideAttrs { + withMpris = false; + withKeyring = false; + }; }; services.spotifyd = { @@ -12,7 +15,6 @@ global = { username_cmd = "cat $CREDENTIALS_DIRECTORY/username"; password_cmd = "cat $CREDENTIALS_DIRECTORY/password"; - backend = "pulseaudio"; bitrate = 320; device_type = "s_t_b"; # set-top box device_name = config.networking.hostName; @@ -27,6 +29,8 @@ ]; }; + networking.firewall.allowedTCPPorts = [4713]; + age.secrets = { spotify-username.file = ../../secrets/spotify-username.age; spotify-password.file = ../../secrets/spotify-password.age;