{ config, lib, pkgs, ... }: let cfg = config.os.core.audio; toggleMuteNotify = pkgs.writeShellScriptBin "toggle-mute-notify" '' IS_MUTED=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep -c "MUTED") if [ "$IS_MUTED" -eq 1 ]; then ${pkgs.libnotify}/bin/notify-send -a "MuteIndicator" -t 0 -u critical "Microphone Muted" "Mic is currently OFF" else ${pkgs.mako}/bin/makoctl dismiss -a "MuteIndicator" fi ''; in { options.os.core.audio = { enable = lib.mkEnableOption "audio support"; disable-devices.enable = lib.mkEnableOption "disables some random devices cluttering up"; }; config = lib.mkMerge [ (lib.mkIf cfg.enable { services.pulseaudio.enable = false; security.rtkit.enable = true; services = { pipewire = { enable = true; audio.enable = true; pulse.enable = true; alsa = { enable = true; support32Bit = true; }; jack.enable = true; wireplumber = { enable = true; extraConfig = { "99-lock-microphone-gain" = { "pulse.rules" = [ { matches = [ { "application.name" = "~*cord*"; } ]; actions = { quirks = [ "no-source-volume" ]; }; } ]; }; "99-disable-suspend" = { "monitor.alsa.rules" = [ { matches = [ { "node.name" = "~alsa_input.*"; } { "node.name" = "~alsa_output.*"; } ]; actions.update-props = { "session.suspend-timeout-seconds" = 0; }; } ]; }; "10-bluetooth-policy" = { "wireplumber.profiles" = { "main" = { "policy.bluetooth" = "enabled"; }; }; "monitor.bluez.properties" = { "bluez5.roles" = [ "a2dp_sink" "a2dp_source" "bap_sink" "bap_source" "hfp_hf" "hsp_hs" ]; "bluez5.codecs" = [ "sbc" "sbc_xq" "aac" "ldac" "aptx" "aptx_hd" ]; }; }; }; }; }; playerctld.enable = true; }; systemd.user.services.pipewire-quantum = { description = "Set strict low-latency PipeWire quantum"; after = [ "wireplumber.service" ]; bindsTo = [ "pipewire.service" ]; wantedBy = [ "wireplumber.service" ]; serviceConfig = { Type = "oneshot"; ExecStart = [ "${pkgs.pipewire}/bin/pw-metadata -n settings 0 clock.quantum 512" "${pkgs.pipewire}/bin/pw-metadata -n settings 0 clock.min-quantum 512" ]; }; }; programs.noisetorch.enable = true; systemd.user.services.pipewire-pulse = { serviceConfig = { Environment = [ "LADSPA_PATH=/tmp" ]; }; }; environment.systemPackages = with pkgs; [ toggleMuteNotify pulsemixer pavucontrol crosspipe alsa-utils ]; }) (lib.mkIf cfg.disable-devices.enable { services.pipewire.wireplumber.extraConfig = { "99-disable-useless-devices"."monitor.alsa.rules" = [ { matches = [ { "device.name" = "~alsa_card.pci-0000_03_00.1*"; } { "device.description" = "~USB Audio*"; } ]; actions.update-props = { "device.disabled" = true; }; } ]; }; }) ]; }