mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-24 06:33:42 +00:00
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
134 lines
3.6 KiB
Nix
134 lines
3.6 KiB
Nix
# ALSA sound support.
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
inherit (pkgs) alsa-utils;
|
|
|
|
pulseaudioEnabled = config.hardware.pulseaudio.enable;
|
|
|
|
in
|
|
|
|
{
|
|
imports = [
|
|
(mkRenamedOptionModule [ "sound" "enableMediaKeys" ] [ "sound" "mediaKeys" "enable" ])
|
|
];
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
sound = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Whether to enable ALSA sound.
|
|
'';
|
|
};
|
|
|
|
enableOSSEmulation = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
|
|
'';
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
type = types.lines;
|
|
default = "";
|
|
example = ''
|
|
defaults.pcm.!card 3
|
|
'';
|
|
description = lib.mdDoc ''
|
|
Set addition configuration for system-wide alsa.
|
|
'';
|
|
};
|
|
|
|
mediaKeys = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Whether to enable volume and capture control with keyboard media keys.
|
|
|
|
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.
|
|
|
|
Enabling this will turn on {option}`services.actkbd`.
|
|
'';
|
|
};
|
|
|
|
volumeStep = mkOption {
|
|
type = types.str;
|
|
default = "1";
|
|
example = "1%";
|
|
description = lib.mdDoc ''
|
|
The value by which to increment/decrement volume on media keys.
|
|
|
|
See amixer(1) for allowed values.
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf config.sound.enable {
|
|
|
|
environment.systemPackages = [ alsa-utils ];
|
|
|
|
environment.etc = mkIf (!pulseaudioEnabled && config.sound.extraConfig != "")
|
|
{ "asound.conf".text = config.sound.extraConfig; };
|
|
|
|
# ALSA provides a udev rule for restoring volume settings.
|
|
services.udev.packages = [ alsa-utils ];
|
|
|
|
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 = "${alsa-utils}/sbin/alsactl store --ignore";
|
|
};
|
|
};
|
|
|
|
services.actkbd = mkIf config.sound.mediaKeys.enable {
|
|
enable = true;
|
|
bindings = [
|
|
# "Mute" media key
|
|
{ keys = [ 113 ]; events = [ "key" ]; command = "${alsa-utils}/bin/amixer -q set Master toggle"; }
|
|
|
|
# "Lower Volume" media key
|
|
{ keys = [ 114 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}- unmute"; }
|
|
|
|
# "Raise Volume" media key
|
|
{ keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}+ unmute"; }
|
|
|
|
# "Mic Mute" media key
|
|
{ keys = [ 190 ]; events = [ "key" ]; command = "${alsa-utils}/bin/amixer -q set Capture toggle"; }
|
|
];
|
|
};
|
|
|
|
};
|
|
|
|
}
|