{
  config,
  lib,
  modulesPath,
  options,
  pkgs,
  specialArgs,
}:

{
  # Enable sound with pipewire and Bluetooth
  hardware.pulseaudio.enable = false;
  services.pipewire.enable = true;
  services.pipewire.alsa.enable = true;
  services.pipewire.pulse.enable = true;

  # Enable pipewire systemwide and allow my user and the login screen to be noisy.
  services.pipewire.systemWide = true;
  users.users.philip.extraGroups = [ "pipewire" ];
  users.users.gdm.extraGroups = [ "pipewire" ];

  services.pipewire.extraConfig.pipewire = {
    "99-input-denoising.conf" = {
      "context.modules" = [
        {
          "name" = "libpipewire-module-filter-chain";
          "args" = {
            "node.description" = "Noise Canceling source";
            "media.name" = "Noise Canceling source";
            "filter.graph" = {
              "nodes" = [
                {
                  "type" = "ladspa";
                  "name" = "rnnoise";
                  "plugin" = "${pkgs.rnnoise-plugin}/lib/ladspa/librnnoise_ladspa.so";
                  "label" = "noise_suppressor_stereo";
                  "control" = {
                    "VAD Threshold (%)" = 50.0;
                  };
                }
              ];
            };
            "audio.position" = [
              "FL"
              "FR"
            ];
            "capture.props" = {
              "node.name" = "effect_input.rnnoise";
              "node.passive" = true;
            };
            "playback.props" = {
              "node.name" = "effect_output.rnnoise";
              "media.class" = "Audio/Source";
            };
          };
        }
      ];
    };
  };

  # RealtimeKit service hands out realtime scheduling priority to user processes on demand.
  # pipewire and wireplumber services use this to acquire realtime priority.
  security.rtkit.enable = true;
}
