e349ccc77f
Eelco Dolstra wrote: Hm, this is not really the intended use of stateVersion. From the description: Every once in a while, a new NixOS release may change configuration defaults in a way incompatible with stateful data. For instance, if the default version of PostgreSQL changes, the new version will probably be unable to read your existing databases. To prevent such breakage, you can set the value of this option to the NixOS release with which you want to be compatible. The effect is that NixOS will option defaults corresponding to the specified release (such as using an older version of PostgreSQL). So this is only intended for options that have some corresponding on-disk state. AFAICT this is not the case for sound. In any case stateVersion is a necessary evil that only exists because we can't just upgrade Postgres databases or change SSH host keys. It's not necessary for things like whether sound is enabled. (If the user discovers that sound is suddenly disabled, they can just enable it.) I had some vague recollection that we also had a configVersion option setting to control the defaults for non-state-related options, but I can't find it so maybe it was only discussed.
129 lines
3.2 KiB
Nix
129 lines
3.2 KiB
Nix
# ALSA sound support.
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
pulseaudioEnabled = config.hardware.pulseaudio.enable;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
sound = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to enable ALSA sound.
|
|
'';
|
|
};
|
|
|
|
enableOSSEmulation = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = ''
|
|
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 = ''
|
|
Set addition configuration for system-wide alsa.
|
|
'';
|
|
};
|
|
|
|
mediaKeys = {
|
|
|
|
enable = 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>.
|
|
'';
|
|
};
|
|
|
|
volumeStep = mkOption {
|
|
type = types.string;
|
|
default = "1";
|
|
example = "1%";
|
|
description = ''
|
|
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 = [ alsaUtils ];
|
|
|
|
environment.etc = mkIf (!pulseaudioEnabled && 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";
|
|
};
|
|
};
|
|
|
|
services.actkbd = mkIf config.sound.mediaKeys.enable {
|
|
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 ${config.sound.mediaKeys.volumeStep}- unmute"; }
|
|
|
|
# "Raise Volume" media key
|
|
{ keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsaUtils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}+ unmute"; }
|
|
|
|
# "Mic Mute" media key
|
|
{ keys = [ 190 ]; events = [ "key" ]; command = "${alsaUtils}/bin/amixer -q set Capture toggle"; }
|
|
];
|
|
};
|
|
|
|
};
|
|
|
|
}
|