nixpkgs/nixos/modules/services/audio/alsa.nix
Eelco Dolstra 29027fd1e1 Rewrite ‘with pkgs.lib’ -> ‘with lib’
Using pkgs.lib on the spine of module evaluation is problematic
because the pkgs argument depends on the result of module
evaluation. To prevent an infinite recursion, pkgs and some of the
modules are evaluated twice, which is inefficient. Using ‘with lib’
prevents this problem.
2014-04-14 16:26:48 +02:00

70 lines
1.4 KiB
Nix

# ALSA sound support.
{ config, lib, pkgs, ... }:
with lib;
let
inherit (pkgs) alsaUtils;
soundState = "/var/lib/alsa/asound.state";
in
{
###### interface
options = {
sound = {
enable = mkOption {
type = types.bool;
default = true;
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!).
'';
};
};
};
###### implementation
config = mkIf config.sound.enable {
environment.systemPackages = [ alsaUtils ];
# 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";
};
};
};
}