2008-11-23 01:29:05 +00:00
|
|
|
# ALSA sound support.
|
2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 18:27:57 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2007-03-01 00:36:00 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-07-16 16:01:56 +01:00
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
2017-06-30 23:01:58 +01:00
|
|
|
pulseaudioEnabled = config.hardware.pulseaudio.enable;
|
|
|
|
|
2009-07-16 16:01:56 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "sound" "enableMediaKeys" ] [ "sound" "mediaKeys" "enable" ])
|
|
|
|
];
|
2009-07-16 16:01:56 +01:00
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
type = types.bool;
|
2018-02-23 21:59:19 +00:00
|
|
|
default = false;
|
2009-07-16 16:01:56 +01:00
|
|
|
description = ''
|
2008-11-23 01:29:05 +00:00
|
|
|
Whether to enable ALSA sound.
|
2009-07-16 16:01:56 +01:00
|
|
|
'';
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-03-03 14:01:13 +00:00
|
|
|
enableOSSEmulation = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
type = types.bool;
|
2020-11-25 22:24:15 +00:00
|
|
|
default = false;
|
2012-08-17 16:00:14 +01:00
|
|
|
description = ''
|
|
|
|
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
|
|
|
|
'';
|
2010-03-03 14:01:13 +00:00
|
|
|
};
|
2007-03-01 00:36:00 +00:00
|
|
|
|
2014-05-23 11:53:24 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2014-05-23 18:20:16 +01:00
|
|
|
default = "";
|
2014-05-23 11:53:24 +01:00
|
|
|
example = ''
|
|
|
|
defaults.pcm.!card 3
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Set addition configuration for system-wide alsa.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-01 10:44:07 +00:00
|
|
|
mediaKeys = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable volume and capture control with keyboard media keys.
|
|
|
|
|
2018-04-25 08:11:49 +01:00
|
|
|
You want to leave this disabled if you run a desktop environment
|
|
|
|
like KDE, Gnome, Xfce, etc, as those handle such things themselves.
|
|
|
|
You might want to enable this if you run a minimalistic desktop
|
|
|
|
environment or work from bare linux ttys/framebuffers.
|
|
|
|
|
2017-01-01 10:44:07 +00:00
|
|
|
Enabling this will turn on <option>services.actkbd</option>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
volumeStep = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2017-01-01 10:44:07 +00:00
|
|
|
default = "1";
|
|
|
|
example = "1%";
|
|
|
|
description = ''
|
|
|
|
The value by which to increment/decrement volume on media keys.
|
|
|
|
|
|
|
|
See amixer(1) for allowed values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 16:01:56 +01:00
|
|
|
###### implementation
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2018-02-23 21:59:19 +00:00
|
|
|
config = mkIf config.sound.enable {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-11-04 17:40:00 +00:00
|
|
|
environment.systemPackages = [ alsaUtils ];
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2017-06-30 23:01:58 +01:00
|
|
|
environment.etc = mkIf (!pulseaudioEnabled && config.sound.extraConfig != "")
|
2020-02-14 00:17:18 +00:00
|
|
|
{ "asound.conf".text = config.sound.extraConfig; };
|
2014-05-23 11:53:24 +01:00
|
|
|
|
2012-10-02 16:09:54 +01:00
|
|
|
# ALSA provides a udev rule for restoring volume settings.
|
|
|
|
services.udev.packages = [ alsaUtils ];
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2012-10-02 16:09:54 +01:00
|
|
|
boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss";
|
2007-03-01 00:36:00 +00:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
systemd.services.alsa-store =
|
2012-10-02 16:09:54 +01:00
|
|
|
{ description = "Store Sound Card State";
|
2013-09-22 20:31:38 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/alsa";
|
2013-11-26 17:17:12 +00:00
|
|
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
2013-09-22 20:31:38 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
|
|
|
|
ExecStop = "${alsaUtils}/sbin/alsactl store --ignore";
|
|
|
|
};
|
2009-07-16 16:01:56 +01:00
|
|
|
};
|
2012-10-09 20:14:32 +01:00
|
|
|
|
2017-01-01 10:44:07 +00:00
|
|
|
services.actkbd = mkIf config.sound.mediaKeys.enable {
|
2015-04-15 18:48:38 +01:00
|
|
|
enable = true;
|
|
|
|
bindings = [
|
|
|
|
# "Mute" media key
|
|
|
|
{ keys = [ 113 ]; events = [ "key" ]; command = "${alsaUtils}/bin/amixer -q set Master toggle"; }
|
|
|
|
|
|
|
|
# "Lower Volume" media key
|
2017-01-01 10:44:07 +00:00
|
|
|
{ keys = [ 114 ]; events = [ "key" "rep" ]; command = "${alsaUtils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}- unmute"; }
|
2015-04-15 18:48:38 +01:00
|
|
|
|
|
|
|
# "Raise Volume" media key
|
2017-01-01 10:44:07 +00:00
|
|
|
{ keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsaUtils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}+ unmute"; }
|
2015-04-15 18:48:38 +01:00
|
|
|
|
|
|
|
# "Mic Mute" media key
|
|
|
|
{ keys = [ 190 ]; events = [ "key" ]; command = "${alsaUtils}/bin/amixer -q set Capture toggle"; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2018-02-23 21:59:19 +00:00
|
|
|
};
|
2007-03-01 00:36:00 +00:00
|
|
|
|
|
|
|
}
|