nixpkgs/nixos/modules/services/audio/alsa.nix

113 lines
2.7 KiB
Nix
Raw Normal View History

# ALSA sound support.
{ config, lib, pkgs, ... }:
with lib;
let
inherit (pkgs) alsaUtils;
in
{
###### interface
options = {
sound = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable ALSA sound.
'';
};
enableOSSEmulation = mkOption {
type = types.bool;
default = true;
2012-08-17 16:00:14 +01:00
description = ''
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
'';
};
enableMediaKeys = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable volume and capture control with keyboard media keys.
Enabling this will turn on <option>services.actkbd</option>.
'';
};
extraConfig = mkOption {
type = types.lines;
default = "";
example = ''
defaults.pcm.!card 3
'';
description = ''
Set addition configuration for system-wide alsa.
'';
};
};
};
###### implementation
config = mkIf config.sound.enable {
environment.systemPackages = [ alsaUtils ];
environment.etc = mkIf (config.sound.extraConfig != "")
[
{ source = pkgs.writeText "asound.conf" config.sound.extraConfig;
target = "asound.conf";
}
];
# ALSA provides a udev rule for restoring volume settings.
services.udev.packages = [ alsaUtils ];
boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss";
systemd.services."alsa-store" =
{ description = "Store Sound Card State";
wantedBy = [ "multi-user.target" ];
unitConfig.RequiresMountsFor = "/var/lib/alsa";
unitConfig.ConditionVirtualization = "!systemd-nspawn";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
ExecStop = "${alsaUtils}/sbin/alsactl store --ignore";
};
};
2012-10-09 20:14:32 +01:00
services.actkbd = mkIf config.sound.enableMediaKeys {
enable = true;
bindings = [
# "Mute" media key
{ keys = [ 113 ]; events = [ "key" ]; command = "${alsaUtils}/bin/amixer -q set Master toggle"; }
# "Lower Volume" media key
{ keys = [ 114 ]; events = [ "key" "rep" ]; command = "${alsaUtils}/bin/amixer -q set Master 1- unmute"; }
# "Raise Volume" media key
{ keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsaUtils}/bin/amixer -q set Master 1+ unmute"; }
# "Mic Mute" media key
{ keys = [ 190 ]; events = [ "key" ]; command = "${alsaUtils}/bin/amixer -q set Capture toggle"; }
];
};
};
}