Files
nix-config/modules/hardware/sound.org
T
phundrak ba018ef841 refactor: change to litterate config
Configuration is now held by the `.org` files. All `.nix` files are
tangled from the org-mode files.
2026-10-06 12:40:58 +02:00

3.0 KiB
Raw Blame History

Sound

Sound

I use Pipewire for audio on my desktop machines, with a couple of compatibility layers and bits of hardware-specific support switched on as needed. Here’s the skeleton of the nixos.sound module.

{
  flake.modules.nixos.sound = {
    lib,
    config,
    pkgs,
    ...
  }:
    with lib; let
      cfg = config.mySystem.hardware.sound;
    in {
      options.mySystem.hardware.sound = {
        <<opt-noisetorch>>
        <<opt-scarlett>>
        <<opt-alsa>>
        <<opt-jack>>
        <<opt-package>>
      };

      config = {
        <<scarlett-package>>
        <<pipewire-config>>
        <<noisetorch-config>>
      };
    };
}

Noise Suppression

noisetorch toggles NoiseTorch, a real-time microphone noise suppression tool I use for calls, so I have an option for that.

noisetorch = mkEnableOption "Whether to activate noisetorch support";

Passing it to NixOS is quite simple.

programs.noisetorch.enable = cfg.noisetorch;

Scarlett Sound Card

scarlett.enable is for the machine marpa with a Focusrite Scarlett 2i2 audio interface plugged in; it only pulls in that card’s control GUI.

scarlett.enable = mkEnableOption "Activate support for Scarlett sound card";

It is installed quite easily in enabled.

environment.systemPackages = mkIf cfg.scarlett.enable [pkgs.alsa-scarlett-gui];

Enabling Pipewire

Enabling Pipewire also means explicitly turning PulseAudio off, since the two can’t run as the system’s sound server at the same time.

services = {
  pipewire = {
    enable = true;
    alsa = mkIf cfg.alsa {
      enable = mkDefault true;
      support32Bit = mkDefault true;
    };
    jack.enable = mkDefault cfg.jack;
  };
  pulseaudio.enable = false;
};

ALSA Compatibility

alsa enables Pipewire’s ALSA compatibility layer, on by default since most of my audio software still expects ALSA.

alsa = mkOption {
  type = types.bool;
  example = true;
  default = true;
  description = "Whether to enable ALSA support with Pipewire";
};

JACK Compatibility

jack enables Pipewire’s JACK compatibility layer, off by default since only my production machine needs it.

jack = mkOption {
  type = types.bool;
  example = true;
  default = false;
  description = "Whether to enable JACK support with Pipewire";
};

Base Package

package picks which PulseAudio package to build things on top of.

package = mkOption {
  type = types.package;
  example = pkgs.pulseaudio;
  default = pkgs.pulseaudioFull;
  description = "Which base package to use for PulseAudio";
};