How to override PulseAudio ALSA files?

WebRTC programs adjust my ALSA mic levels incorrectly.

To disable that, I essentially need to modify alsa-mixer .conf files, such as /nix/store/vg3q364zl6q9lnsfcy1vg7f5a3jj9448-pulseaudio-12.2/share/pulseaudio/alsa-mixer/paths/analog-output.conf

Does anybody know whether I can place/override these files somewhere else?

Right now, modifying them seems to require rebuilding pulse, and all of its dependencies.

Details on the change I likely need:

Did you ever find out a way how to do it?
I need to change analog-output.conf.common in the same path because of an issue with volume control on some Asus notebooks (, basically switch from controlling Master to controlling PCM instead will do the trick, but for that I need to edit the file. I run into the same issue that to simply modify the file, it requires rebuilding a lot of stuff.
Is there any way how to do it without rebuilding?
I’m surprised noone else ran into this problem, maybe Asus is not a brand of choice for NixOS enthusiasts? :slight_smile:

Hey, yes, I do have a workaround for that:

Doing pulseaudio.overrideAttrs and overriding buildCommand to not do any building, but instead copying the already-built files from the original derivation with cp.

Here is a concrete example which shows this technique on pulseaudio (it should also work for other packages) and also handles split-outputs (-out, -dev and so on):

  # Trying to have pulseaudio forbid Chromium to adjust volume gain,
  # but so far none of these have been effective.
  # See
  puseaudio_with_mic_boost_disabled =
      constantVolume = 40;
    pkgs.pulseaudio.overrideAttrs (old: {
      # name = "pulseaudio-patched";
      name = "${}-patched-without-mic-boost";
      # Instead of overriding some post-build action, which would require a
      # pulseaudio rebuild, we override the entire `buildCommand` to produce
      # its outputs by copying the original package's files (much faster).
      buildCommand = ''
        set -euo pipefail

        ${# Copy original files, for each split-output (`out`, `dev` etc.).
          lib.concatStringsSep "\n"
                  echo "Copying output ${outputName}"
                  set -x
                  cp -a ${pkgs.pulseaudio.${outputName}} ''$${outputName}
                  set +x

        # Replace:
        #     [Element Capture]
        #     switch = mute
        #     volume = merge
        # by:
        #     [Element Capture]
        #     switch = mute
        #     volume = ${toString constantVolume}
        # The target file `analog-input-internal-mic.conf` should be determined
        # by the output of `pacmd list-sources` for the relevant microphone `index:`,
        # which for my microphone is:
        #     active port: <analog-input-internal-mic>
        set -x
        cat $INFILE \
          | ${pkgs.python3}/bin/python -c 'import re,sys; print(re.sub(r"\[Element Capture\]\nswitch = mute\nvolume = merge", "[Element Capture]\nswitch = mute\nvolume = ${toString constantVolume}",' \
          > tmp.conf
        # Ensure file changed (something was replaced)
        ! cmp tmp.conf $INFILE
        chmod +w $out/share/pulseaudio/alsa-mixer/paths/analog-input-internal-mic.conf
        cp tmp.conf $INFILE
        set +x

And then I can use it for my system using:

  hardware.pulseaudio.package = puseaudio_with_mic_boost_disabled;

(Note that the concrete thing that I’m trying to do here, forbidding Chromium WebRTC to adjust my volume, still doesn’t seem to be working, but it does override PulseAudio ALSA file contents successfully.)

1 Like

Wow, thanks a lot! I will test it next week when I’ll get to the notebook in question but this is exactly what I was hoping for.