88 lines
2.8 KiB
Nix
88 lines
2.8 KiB
Nix
{ config, lib, options, pkgs, ... }:
|
|
|
|
let
|
|
cfg = config.c3d2.audioStreaming;
|
|
isGraphical = config.services.xserver.enable || (config.services.displayManager.defaultSession or config.services.xserver.displayManager.defaultSession) != null;
|
|
|
|
hasExtraConfig = options.services.pipewire?extraConfig;
|
|
zeroconfConfig = {
|
|
"context.modules" = [ {
|
|
"name" = "libpipewire-module-zeroconf-discover";
|
|
} ];
|
|
};
|
|
in
|
|
{
|
|
options = {
|
|
c3d2.audioStreaming = lib.mkEnableOption "enable all services requires to audio stream to dacbert, glotzert or pulsebert";
|
|
};
|
|
|
|
config = lib.mkIf cfg {
|
|
environment.etc = lib.mkIf (!hasExtraConfig) {
|
|
"pipewire/pipewire.conf.d/zeroconf.conf".text = builtins.toJSON zeroconfConfig;
|
|
};
|
|
|
|
environment.systemPackages = lib.mkIf isGraphical (with pkgs; [
|
|
paprefs
|
|
pavucontrol
|
|
# https://wiki.archlinux.org/title/PulseAudio/Examples#PulseAudio_over_network
|
|
(pkgs.writeScriptBin "enable-pipebert-rtp" /* bash */ ''
|
|
set -eou pipefail
|
|
export PATH=$PATH:${lib.makeBinPath [ config.hardware.pulseaudio.package dig ]}
|
|
|
|
ip=$(dig +short pipebert.hq.c3d2.de)
|
|
|
|
pactl load-module module-null-sink sink_name=rtp sink_properties="node.description='Pipebert\ RTP\ Stream'"
|
|
pactl load-module module-rtp-send source=rtp.monitor destination_ip="$ip" port=9875
|
|
'')
|
|
(pkgs.writeScriptBin "disable-pipebert-rtp" /* bash */ ''
|
|
set -eou pipefail
|
|
export PATH=$PATH:${lib.makeBinPath [ config.hardware.pulseaudio.package ]}
|
|
|
|
pactl unload-module module-rtp-send
|
|
pactl unload-module module-null-sink
|
|
'')
|
|
]);
|
|
|
|
hardware.pulseaudio = {
|
|
# enabling zeroconf discovery or publishing turns on zeroconfSupport for the configured pulseaudio package
|
|
# pulseaudioFull has that enabled plus it has a cache hit on cache.nixos.org
|
|
package = pkgs.pulseaudioFull;
|
|
zeroconf.discovery.enable = true;
|
|
};
|
|
|
|
# required for paprefs to be able to save
|
|
programs.dconf = lib.mkIf isGraphical {
|
|
enable = true;
|
|
profiles.user.databases = [{
|
|
settings."org/freedesktop/pulseaudio/module-groups/zeroconf-discover" = {
|
|
args0 = "";
|
|
enabled = true;
|
|
name0 = "module-zeroconf-discover";
|
|
};
|
|
}];
|
|
};
|
|
|
|
security.rtkit.enable = true;
|
|
|
|
services = {
|
|
avahi = let
|
|
nssmdns = if lib.hasAttr "nssmdns4" options.services.avahi then "nssmdns4" else "nssmdns";
|
|
in {
|
|
enable = true;
|
|
"${nssmdns}" = true;
|
|
};
|
|
|
|
pipewire = lib.optionalAttrs hasExtraConfig {
|
|
extraConfig.pipewire.zeroconf = zeroconfConfig;
|
|
}// {
|
|
pulse.enable = true;
|
|
};
|
|
|
|
# makes avahi unreliable
|
|
resolved.extraConfig = ''
|
|
MulticastDNS=no
|
|
'';
|
|
};
|
|
};
|
|
}
|