nix-user-module/modules/audio.nix

78 lines
2.4 KiB
Nix
Raw Normal View History

{ config, lib, options, pkgs, ... }:
2023-01-03 05:16:12 +01:00
let
cfg = config.c3d2.audioStreaming;
in
{
options = {
c3d2.audioStreaming = lib.mkEnableOption "enable all services requires to audio stream to dacbert, glotzert or pulsebert";
2023-01-03 05:16:12 +01:00
};
config = lib.mkIf cfg {
2023-12-19 23:05:29 +01:00
environment.etc."pipewire/pipewire.conf.d/zeroconf.conf".text = builtins.toJSON {
"context.modules" = [ {
"name" = "libpipewire-module-zeroconf-discover";
} ];
};
environment.systemPackages = lib.mkIf config.services.xserver.enable (with pkgs; [
paprefs
pavucontrol
2023-12-13 20:33:56 +01:00
# https://wiki.archlinux.org/title/PulseAudio/Examples#PulseAudio_over_network
2023-12-13 20:32:57 +01:00
(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)
2023-12-17 17:18:41 +01:00
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
2023-12-13 20:32:57 +01:00
'')
2023-12-17 17:03:44 +01:00
(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;
};
2023-01-03 05:16:12 +01:00
# required for paprefs to be able to save
2023-12-19 23:05:29 +01:00
programs.dconf = lib.mkIf config.services.xserver.enable {
enable = true;
profiles.user.databases = [{
settings."org/freedesktop/pulseaudio/module-groups/zeroconf-discover" = {
args0 = "";
enabled = true;
name0 = "module-zeroconf-discover";
};
}];
};
2023-01-03 05:16:12 +01:00
security.rtkit.enable = true;
services = {
avahi = let
nssmdns = if lib.hasAttr "nssmdns4" options.services.avahi then "nssmdns4" else "nssmdns";
in {
2023-01-03 05:16:12 +01:00
enable = true;
"${nssmdns}" = true;
2023-01-03 05:16:12 +01:00
};
2023-12-19 23:05:29 +01:00
pipewire.pulse.enable = true;
# makes avahi unreliable
resolved.extraConfig = ''
MulticastDNS=no
'';
2023-01-03 05:16:12 +01:00
};
};
}